diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt index 3c6ef0cc6..b70a32c39 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt @@ -37,13 +37,15 @@ public interface SelectableColumnOnKeyEvent { val newSelection = ArrayList(max(initialIndex, state.selectedKeys.size)).apply { addAll(state.selectedKeys) } + var lastActiveItemIndex = initialIndex for (index in initialIndex - 1 downTo 0) { val key = keys[index] if (key is Selectable) { newSelection.add(key.key) - state.lastActiveItemIndex = index + lastActiveItemIndex = index } } + state.lastActiveItemIndex = lastActiveItemIndex state.selectedKeys = newSelection } @@ -76,13 +78,15 @@ public interface SelectableColumnOnKeyEvent { val newSelection = ArrayList(max(keys.size - initialIndex, state.selectedKeys.size)).apply { addAll(state.selectedKeys) } + var lastActiveItemIndex = initialIndex for (index in initialIndex + 1..keys.lastIndex) { val key = keys[index] if (key is Selectable) { newSelection.add(key.key) - state.lastActiveItemIndex = index + lastActiveItemIndex = index } } + state.lastActiveItemIndex = lastActiveItemIndex state.selectedKeys = newSelection }