Skip to content

Commit 841d833

Browse files
committed
fix(gui): improve focus handling in AutoDevInputSection #51
The focus handling logic in the AutoDevInputSection has been refactored to directly request focus from the IdeFocusManager and to move the caret to the end of the input text. Additionally, the component popup builder now sets cancel on click outside and cancel on window deactivation to true for a better user experience.
1 parent 2786715 commit 841d833

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
138138
val horizontalGlue = Box.createHorizontalGlue()
139139
horizontalGlue.addMouseListener(object : MouseAdapter() {
140140
override fun mouseClicked(e: MouseEvent?) {
141-
val ideFocusManager = IdeFocusManager.getInstance(project)
142-
ideFocusManager.requestFocus(input, true)
141+
IdeFocusManager.getInstance(project).requestFocus(input, true)
142+
input.caretModel.moveToOffset(input.text.length - 1)
143143
}
144144
})
145145
layoutPanel.background = JBColor(
@@ -201,8 +201,9 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
201201
text += "${selectedItem.customVariable.variable} "
202202
}
203203

204-
this@AutoDevInputSection.input.requestFocus()
205204
this@AutoDevInputSection.popup?.cancel()
205+
input.requestFocus()
206+
input.caretModel.moveToOffset(input.text.length - 1)
206207
}
207208

208209
KeyEvent.VK_DOWN -> {
@@ -230,6 +231,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
230231
.createComponentPopupBuilder(list, null)
231232
.setFocusable(true)
232233
.setRequestFocus(true)
234+
.setCancelOnClickOutside(true)
235+
.setCancelOnWindowDeactivation(true)
233236
.setMinSize(Dimension(this@AutoDevInputSection.width, 0))
234237
.createPopup()
235238

0 commit comments

Comments
 (0)