diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/KeyActions.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/KeyActions.kt index 5053fbbf6..da45561e7 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/KeyActions.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/KeyActions.kt @@ -278,6 +278,24 @@ open class DefaultSelectableLazyColumnKeyActions( keys: List, state: SelectableLazyListState, selectionMode: SelectionMode, + ): Boolean { + val singleSelectionEventHandled = handleSingleSelectionEvents(keys, state) + if (singleSelectionEventHandled) { + return true + } + if (selectionMode == SelectionMode.Multiple) { + val multipleSelectionEventHandled = handleMultipleSelectionEvents(keys, state) + if (multipleSelectionEventHandled) { + return true + } + } + return false + } + + context(SelectableColumnKeybindings, SelectableColumnOnKeyEvent) + private fun KeyEvent.handleSingleSelectionEvents( + keys: List, + state: SelectableLazyListState, ): Boolean { when { isSelectNextItem -> onSelectNextItem(keys, state) @@ -285,20 +303,27 @@ open class DefaultSelectableLazyColumnKeyActions( isSelectFirstItem -> onSelectFirstItem(keys, state) isSelectLastItem -> onSelectLastItem(keys, state) isEdit -> onEdit() + else -> return false } - if (selectionMode == SelectionMode.Multiple) { - when { - isExtendSelectionToFirstItem -> onExtendSelectionToFirst(keys, state) - isExtendSelectionToLastItem -> onExtendSelectionToLastItem(keys, state) - isExtendSelectionWithNextItem -> onExtendSelectionWithNextItem(keys, state) - isExtendSelectionWithPreviousItem -> onExtendSelectionWithPreviousItem(keys, state) - isScrollPageDownAndExtendSelection -> onScrollPageDownAndExtendSelection(keys, state) - isScrollPageDownAndSelectItem -> onScrollPageDownAndSelectItem(keys, state) - isScrollPageUpAndExtendSelection -> onScrollPageUpAndExtendSelection(keys, state) - isScrollPageUpAndSelectItem -> onScrollPageUpAndSelectItem(keys, state) - isSelectAll -> onSelectAll(keys, state) - else -> return false - } + return true + } + + context(SelectableColumnKeybindings, SelectableColumnOnKeyEvent) + private fun KeyEvent.handleMultipleSelectionEvents( + keys: List, + state: SelectableLazyListState, + ): Boolean { + when { + isExtendSelectionToFirstItem -> onExtendSelectionToFirst(keys, state) + isExtendSelectionToLastItem -> onExtendSelectionToLastItem(keys, state) + isExtendSelectionWithNextItem -> onExtendSelectionWithNextItem(keys, state) + isExtendSelectionWithPreviousItem -> onExtendSelectionWithPreviousItem(keys, state) + isScrollPageDownAndExtendSelection -> onScrollPageDownAndExtendSelection(keys, state) + isScrollPageDownAndSelectItem -> onScrollPageDownAndSelectItem(keys, state) + isScrollPageUpAndExtendSelection -> onScrollPageUpAndExtendSelection(keys, state) + isScrollPageUpAndSelectItem -> onScrollPageUpAndSelectItem(keys, state) + isSelectAll -> onSelectAll(keys, state) + else -> return false } return true }