From 1f74f9fff2348ff04b770a81da81f4b664b2cd84 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 6 Mar 2024 22:48:52 +0800 Subject: [PATCH] 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. --- .../kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt b/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt index 0a3da1b90f..d0f9a2a527 100644 --- a/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt +++ b/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt @@ -191,6 +191,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab override fun keyPressed(e: KeyEvent?) { if (!hasPopup()) return + val itemsCount = list.getItemsCount() + when (e?.keyCode) { KeyEvent.VK_ENTER -> { e.consume() @@ -205,7 +207,6 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab KeyEvent.VK_DOWN -> { val selectedIndex = list.selectedIndex - val itemsCount = list.getItemsCount() if (selectedIndex < itemsCount - 1) { list.setSelectedIndex(selectedIndex + 1) } else { @@ -218,7 +219,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab if (selectedIndex > 0) { list.setSelectedIndex(selectedIndex - 1) } else { - list.setSelectedIndex(list.getItemsCount() - 1) + list.setSelectedIndex(itemsCount - 1) } } }