Skip to content

Commit 1f74f9f

Browse files
committed
fix(gui): ensure correct selection in AutoDevInputSection #51
The `AutoDevInputSection` now correctly handles the selection of items in the list, regardless of the number of items present. Previously, the selected index was not being updated correctly when reaching the last or first item in the list. This has been fixed by using the actual count of items in the list instead of a hardcoded value.
1 parent c8b38e9 commit 1f74f9f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
191191
override fun keyPressed(e: KeyEvent?) {
192192
if (!hasPopup()) return
193193

194+
val itemsCount = list.getItemsCount()
195+
194196
when (e?.keyCode) {
195197
KeyEvent.VK_ENTER -> {
196198
e.consume()
@@ -205,7 +207,6 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
205207

206208
KeyEvent.VK_DOWN -> {
207209
val selectedIndex = list.selectedIndex
208-
val itemsCount = list.getItemsCount()
209210
if (selectedIndex < itemsCount - 1) {
210211
list.setSelectedIndex(selectedIndex + 1)
211212
} else {
@@ -218,7 +219,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
218219
if (selectedIndex > 0) {
219220
list.setSelectedIndex(selectedIndex - 1)
220221
} else {
221-
list.setSelectedIndex(list.getItemsCount() - 1)
222+
list.setSelectedIndex(itemsCount - 1)
222223
}
223224
}
224225
}

0 commit comments

Comments
 (0)