From 0c53c14e630d6dfc642ea7db152dd20da296a405 Mon Sep 17 00:00:00 2001 From: Nikolay Rykunov Date: Fri, 3 Nov 2023 12:04:10 +0100 Subject: [PATCH] Don't update state in loop --- .../jewel/foundation/lazy/SelectableColumnOnKeyEvent.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 }