Skip to content

Commit 78987d7

Browse files
authored
Revert enter behavior on multi-select (#4386)
1 parent b906a34 commit 78987d7

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
@@ -353,6 +353,7 @@ class _SelectionList(SelectionList[ValueT]):
353353
Binding('up', 'cursor_up', 'Up', show=True),
354354
Binding('j', 'cursor_down', 'Down', show=False),
355355
Binding('k', 'cursor_up', 'Up', show=False),
356+
Binding('space', 'select', 'Toggle', show=True),
356357
]
357358

358359

@@ -503,9 +504,18 @@ def on_mount(self) -> None:
503504
self.query_one(SelectionList).focus()
504505

505506
def on_key(self, event: Key) -> None:
506-
if self.query_one(SelectionList).has_focus:
507-
if event.key == 'enter':
508-
_ = self.dismiss(Result(ResultType.Selection, _item=self._selected_items))
507+
selection_list = self.query_one(SelectionList)
508+
509+
if not selection_list.has_focus or event.key != 'enter':
510+
return None
511+
512+
if len(self._selected_items) < 1:
513+
index = selection_list.highlighted
514+
if index is not None:
515+
selection = selection_list.get_option_at_index(index)
516+
self._selected_items.append(selection.value)
517+
518+
_ = self.dismiss(Result(ResultType.Selection, _item=self._selected_items))
509519

510520
def on_input_changed(self, event: Input.Changed) -> None:
511521
search_term = event.value.lower()
@@ -858,12 +868,14 @@ class _DataTable(DataTable[ValueT]):
858868
Binding('up', 'cursor_up', 'Up', show=True),
859869
Binding('j', 'cursor_down', 'Down', show=False),
860870
Binding('k', 'cursor_up', 'Up', show=False),
871+
Binding('space', 'select', 'Toggle', show=True),
872+
Binding('enter', 'select_cursor', 'Confirm', show=True),
861873
]
862874

863875

864876
class TableSelectionScreen(BaseScreen[ValueT]):
865877
BINDINGS: ClassVar = [
866-
Binding('space', 'toggle_selection', 'Toggle', show=True),
878+
Binding('space', 'toggle_selection', 'Toggle', show=True), # expclit handling of space in multi-selection mode
867879
]
868880

869881
CSS = """
@@ -1103,20 +1115,18 @@ def _set_cursor(self, row_index: int) -> None:
11031115
def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
11041116
if self._multi:
11051117
if len(self._selected_keys) == 0:
1106-
if not self._allow_skip:
1107-
return
1108-
1109-
_ = self.dismiss(Result[ValueT](ResultType.Skip))
1118+
selection = [event.row_key.value]
11101119
else:
1111-
items = [row_key.value for row_key in self._selected_keys]
1112-
_ = self.dismiss(Result(ResultType.Selection, _item=items)) # type: ignore[arg-type]
1120+
selection = [row_key.value for row_key in self._selected_keys]
11131121
else:
1114-
_ = self.dismiss(
1115-
Result[ValueT](
1116-
ResultType.Selection,
1117-
_item=event.row_key.value, # type: ignore[arg-type]
1118-
)
1122+
selection = event.row_key.value # type: ignore[assignment]
1123+
1124+
_ = self.dismiss(
1125+
Result[ValueT](
1126+
ResultType.Selection,
1127+
_item=selection, # type: ignore[arg-type]
11191128
)
1129+
)
11201130

11211131

11221132
class InstanceRunnable[ValueT](ABC):

0 commit comments

Comments
 (0)