Skip to content

Commit 503a8ad

Browse files
committed
Revert enter behavior on multi-select
1 parent dd0da34 commit 503a8ad

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

archinstall/tui/ui/components.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ class _SelectionList(SelectionList[ValueT]):
347347
Binding('up', 'cursor_up', 'Up', show=True),
348348
Binding('j', 'cursor_down', 'Down', show=False),
349349
Binding('k', 'cursor_up', 'Up', show=False),
350+
Binding('space', 'select', 'Toggle', show=True),
350351
]
351352

352353

@@ -493,9 +494,18 @@ def on_mount(self) -> None:
493494
self.query_one(SelectionList).focus()
494495

495496
def on_key(self, event: Key) -> None:
496-
if self.query_one(SelectionList).has_focus:
497-
if event.key == 'enter':
498-
_ = self.dismiss(Result(ResultType.Selection, _item=self._selected_items))
497+
selection_list = self.query_one(SelectionList)
498+
499+
if not selection_list.has_focus or event.key != 'enter':
500+
return None
501+
502+
if len(self._selected_items) < 1:
503+
index = selection_list.highlighted
504+
if index is not None:
505+
selection = selection_list.get_option_at_index(index)
506+
self._selected_items.append(selection.value)
507+
508+
_ = self.dismiss(Result(ResultType.Selection, _item=self._selected_items))
499509

500510
def on_input_changed(self, event: Input.Changed) -> None:
501511
search_term = event.value.lower()
@@ -842,12 +852,14 @@ class _DataTable(DataTable[ValueT]):
842852
Binding('up', 'cursor_up', 'Up', show=True),
843853
Binding('j', 'cursor_down', 'Down', show=False),
844854
Binding('k', 'cursor_up', 'Up', show=False),
855+
Binding('space', 'select', 'Toggle', show=True),
856+
Binding('enter', 'select_cursor', 'Confirm', show=True),
845857
]
846858

847859

848860
class TableSelectionScreen(BaseScreen[ValueT]):
849861
BINDINGS: ClassVar = [
850-
Binding('space', 'toggle_selection', 'Toggle', show=True),
862+
Binding('space', 'toggle_selection', 'Toggle', show=True), # expclit handling of space in multi-selection mode
851863
]
852864

853865
CSS = """
@@ -1087,20 +1099,18 @@ def _set_cursor(self, row_index: int) -> None:
10871099
def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
10881100
if self._multi:
10891101
if len(self._selected_keys) == 0:
1090-
if not self._allow_skip:
1091-
return
1092-
1093-
_ = self.dismiss(Result[ValueT](ResultType.Skip))
1102+
selection = [event.row_key.value]
10941103
else:
1095-
items = [row_key.value for row_key in self._selected_keys]
1096-
_ = self.dismiss(Result(ResultType.Selection, _item=items)) # type: ignore[arg-type]
1104+
selection = [row_key.value for row_key in self._selected_keys]
10971105
else:
1098-
_ = self.dismiss(
1099-
Result[ValueT](
1100-
ResultType.Selection,
1101-
_item=event.row_key.value, # type: ignore[arg-type]
1102-
)
1106+
selection = event.row_key.value # type: ignore[assignment]
1107+
1108+
_ = self.dismiss(
1109+
Result[ValueT](
1110+
ResultType.Selection,
1111+
_item=selection, # type: ignore[arg-type]
11031112
)
1113+
)
11041114

11051115

11061116
class InstanceRunnable[ValueT](ABC):

0 commit comments

Comments
 (0)