Skip to content

fix: Unable to receive notifications when changes are made to the doc… #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/main/kotlin/cc/unitmesh/devti/settings/LLMParamComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package cc.unitmesh.devti.settings

import cc.unitmesh.devti.AutoDevBundle
import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.components.JBPasswordField
import com.intellij.ui.components.JBTextField
import java.awt.event.ItemEvent
import javax.swing.event.DocumentEvent
import kotlin.properties.PropertyDelegateProvider
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
Expand Down Expand Up @@ -38,9 +40,9 @@ fun ReactiveTextField(param: LLMParam, initBlock: JBTextField.(LLMParam) -> Unit

component.initBlock(reactive)

component.document.addUndoableEditListener {
component.document.addDocumentListener(CustomDocumentListener{
param.value = component.text
}
})
return component
}

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

component.initBlock(reactive.value)
component.document.addUndoableEditListener {
if (component.password.joinToString("") == param.value) return@addUndoableEditListener
component.document.addDocumentListener(CustomDocumentListener{
if (component.password.joinToString("") == param.value) return@CustomDocumentListener
reactive.value.value = component.password.joinToString("")
}
})

return component
}
Expand All @@ -78,6 +80,12 @@ fun ReactiveComboBox(param: LLMParam, initBlock: ComboBox<String>.(LLMParam) ->
return component
}

class CustomDocumentListener(val onChange: () -> Unit) : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
onChange()
}
}


/**
*
Expand Down
Loading