Skip to content

Commit

Permalink
Fix events handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Walingar committed Nov 2, 2023
1 parent ba77d9b commit 8c646c1
Showing 1 changed file with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,27 +278,52 @@ open class DefaultSelectableLazyColumnKeyActions(
keys: List<SelectableLazyListKey>,
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<SelectableLazyListKey>,
state: SelectableLazyListState,
): Boolean {
when {
isSelectNextItem -> onSelectNextItem(keys, state)
isSelectPreviousItem -> onSelectPreviousItem(keys, state)
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<SelectableLazyListKey>,
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
}
Expand Down

0 comments on commit 8c646c1

Please sign in to comment.