Skip to content

Commit 22cd295

Browse files
authored
fix: Unable to receive notifications when changes are made to the document (#228)
1 parent 04fb256 commit 22cd295

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/kotlin/cc/unitmesh/devti/settings/LLMParamComponent.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package cc.unitmesh.devti.settings
22

33
import cc.unitmesh.devti.AutoDevBundle
44
import com.intellij.openapi.ui.ComboBox
5+
import com.intellij.ui.DocumentAdapter
56
import com.intellij.ui.components.JBPasswordField
67
import com.intellij.ui.components.JBTextField
78
import java.awt.event.ItemEvent
9+
import javax.swing.event.DocumentEvent
810
import kotlin.properties.PropertyDelegateProvider
911
import kotlin.properties.ReadOnlyProperty
1012
import kotlin.reflect.KProperty
@@ -38,9 +40,9 @@ fun ReactiveTextField(param: LLMParam, initBlock: JBTextField.(LLMParam) -> Unit
3840

3941
component.initBlock(reactive)
4042

41-
component.document.addUndoableEditListener {
43+
component.document.addDocumentListener(CustomDocumentListener{
4244
param.value = component.text
43-
}
45+
})
4446
return component
4547
}
4648

@@ -53,10 +55,10 @@ fun ReactivePasswordField(param: LLMParam, initBlock: JBPasswordField.(LLMParam)
5355
}
5456

5557
component.initBlock(reactive.value)
56-
component.document.addUndoableEditListener {
57-
if (component.password.joinToString("") == param.value) return@addUndoableEditListener
58+
component.document.addDocumentListener(CustomDocumentListener{
59+
if (component.password.joinToString("") == param.value) return@CustomDocumentListener
5860
reactive.value.value = component.password.joinToString("")
59-
}
61+
})
6062

6163
return component
6264
}
@@ -78,6 +80,12 @@ fun ReactiveComboBox(param: LLMParam, initBlock: ComboBox<String>.(LLMParam) ->
7880
return component
7981
}
8082

83+
class CustomDocumentListener(val onChange: () -> Unit) : DocumentAdapter() {
84+
override fun textChanged(e: DocumentEvent) {
85+
onChange()
86+
}
87+
}
88+
8189

8290
/**
8391
*

0 commit comments

Comments
 (0)