Revert enter behavior on multi-select (#4386)
This commit is contained in:
parent
b906a34a5d
commit
78987d75fe
|
|
@ -353,6 +353,7 @@ class _SelectionList(SelectionList[ValueT]):
|
||||||
Binding('up', 'cursor_up', 'Up', show=True),
|
Binding('up', 'cursor_up', 'Up', show=True),
|
||||||
Binding('j', 'cursor_down', 'Down', show=False),
|
Binding('j', 'cursor_down', 'Down', show=False),
|
||||||
Binding('k', 'cursor_up', 'Up', show=False),
|
Binding('k', 'cursor_up', 'Up', show=False),
|
||||||
|
Binding('space', 'select', 'Toggle', show=True),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -503,9 +504,18 @@ class SelectListScreen(BaseScreen[ValueT]):
|
||||||
self.query_one(SelectionList).focus()
|
self.query_one(SelectionList).focus()
|
||||||
|
|
||||||
def on_key(self, event: Key) -> None:
|
def on_key(self, event: Key) -> None:
|
||||||
if self.query_one(SelectionList).has_focus:
|
selection_list = self.query_one(SelectionList)
|
||||||
if event.key == 'enter':
|
|
||||||
_ = self.dismiss(Result(ResultType.Selection, _item=self._selected_items))
|
if not selection_list.has_focus or event.key != 'enter':
|
||||||
|
return None
|
||||||
|
|
||||||
|
if len(self._selected_items) < 1:
|
||||||
|
index = selection_list.highlighted
|
||||||
|
if index is not None:
|
||||||
|
selection = selection_list.get_option_at_index(index)
|
||||||
|
self._selected_items.append(selection.value)
|
||||||
|
|
||||||
|
_ = self.dismiss(Result(ResultType.Selection, _item=self._selected_items))
|
||||||
|
|
||||||
def on_input_changed(self, event: Input.Changed) -> None:
|
def on_input_changed(self, event: Input.Changed) -> None:
|
||||||
search_term = event.value.lower()
|
search_term = event.value.lower()
|
||||||
|
|
@ -858,12 +868,14 @@ class _DataTable(DataTable[ValueT]):
|
||||||
Binding('up', 'cursor_up', 'Up', show=True),
|
Binding('up', 'cursor_up', 'Up', show=True),
|
||||||
Binding('j', 'cursor_down', 'Down', show=False),
|
Binding('j', 'cursor_down', 'Down', show=False),
|
||||||
Binding('k', 'cursor_up', 'Up', show=False),
|
Binding('k', 'cursor_up', 'Up', show=False),
|
||||||
|
Binding('space', 'select', 'Toggle', show=True),
|
||||||
|
Binding('enter', 'select_cursor', 'Confirm', show=True),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class TableSelectionScreen(BaseScreen[ValueT]):
|
class TableSelectionScreen(BaseScreen[ValueT]):
|
||||||
BINDINGS: ClassVar = [
|
BINDINGS: ClassVar = [
|
||||||
Binding('space', 'toggle_selection', 'Toggle', show=True),
|
Binding('space', 'toggle_selection', 'Toggle', show=True), # expclit handling of space in multi-selection mode
|
||||||
]
|
]
|
||||||
|
|
||||||
CSS = """
|
CSS = """
|
||||||
|
|
@ -1103,20 +1115,18 @@ class TableSelectionScreen(BaseScreen[ValueT]):
|
||||||
def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
|
def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
|
||||||
if self._multi:
|
if self._multi:
|
||||||
if len(self._selected_keys) == 0:
|
if len(self._selected_keys) == 0:
|
||||||
if not self._allow_skip:
|
selection = [event.row_key.value]
|
||||||
return
|
|
||||||
|
|
||||||
_ = self.dismiss(Result[ValueT](ResultType.Skip))
|
|
||||||
else:
|
else:
|
||||||
items = [row_key.value for row_key in self._selected_keys]
|
selection = [row_key.value for row_key in self._selected_keys]
|
||||||
_ = self.dismiss(Result(ResultType.Selection, _item=items)) # type: ignore[arg-type]
|
|
||||||
else:
|
else:
|
||||||
_ = self.dismiss(
|
selection = event.row_key.value # type: ignore[assignment]
|
||||||
Result[ValueT](
|
|
||||||
ResultType.Selection,
|
_ = self.dismiss(
|
||||||
_item=event.row_key.value, # type: ignore[arg-type]
|
Result[ValueT](
|
||||||
)
|
ResultType.Selection,
|
||||||
|
_item=selection, # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InstanceRunnable[ValueT](ABC):
|
class InstanceRunnable[ValueT](ABC):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue