Skip to content

Commit

Permalink
fix(gui): ensure correct selection in AutoDevInputSection #51
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 6, 2024
1 parent c8b38e9 commit 1f74f9f
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 1f74f9f

Please sign in to comment.