Skip to content

Commit

Permalink
Don't update state in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Walingar committed Nov 3, 2023
1 parent f10058a commit 0c53c14
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ public interface SelectableColumnOnKeyEvent {
val newSelection = ArrayList<Any>(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
}

Expand Down Expand Up @@ -76,13 +78,15 @@ public interface SelectableColumnOnKeyEvent {
val newSelection = ArrayList<Any>(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
}

Expand Down

0 comments on commit 0c53c14

Please sign in to comment.