diff --git a/InquirerPy/base/list.py b/InquirerPy/base/list.py index b3d94d0..7a44a06 100644 --- a/InquirerPy/base/list.py +++ b/InquirerPy/base/list.py @@ -91,21 +91,21 @@ def __init__( {"key": "k", "filter": self._is_vim_edit}, ], "toggle": [ - {"key": "space", "filter": self._is_multiselect}, + {"key": "space"}, ], "toggle-down": [ - {"key": Keys.Tab, "filter": self._is_multiselect}, + {"key": Keys.Tab}, ], "toggle-up": [ - {"key": Keys.BackTab, "filter": self._is_multiselect}, + {"key": Keys.BackTab}, ], "toggle-all": [ - {"key": "alt-r", "filter": self._is_multiselect}, - {"key": "c-r", "filter": self._is_multiselect}, + {"key": "alt-r"}, + {"key": "c-r"}, ], "toggle-all-true": [ - {"key": "alt-a", "filter": self._is_multiselect}, - {"key": "c-a", "filter": self._is_multiselect}, + {"key": "alt-a"}, + {"key": "c-a"}, ], "toggle-all-false": [], **keybindings, diff --git a/InquirerPy/prompts/fuzzy.py b/InquirerPy/prompts/fuzzy.py index 6919b13..6940dbf 100644 --- a/InquirerPy/prompts/fuzzy.py +++ b/InquirerPy/prompts/fuzzy.py @@ -484,16 +484,19 @@ def _on_rendered(self, _) -> None: self._buffer.text = default_text self._buffer.cursor_position = len(default_text) - def _handle_toggle_all(self, _, value: bool = None) -> None: + def _handle_toggle_all(self, event, value: bool = None) -> None: """Toggle all choice `enabled` status. Args: value: Specify the value to toggle. """ - for choice in self.content_control.choices: - if isinstance(choice["value"], Separator): + if not self._multiselect: + return + for choice in self.content_control._filtered_choices: + raw_choice = self.content_control.choices[choice["index"]] + if isinstance(raw_choice["value"], Separator): continue - choice["enabled"] = value if value else not choice["enabled"] + raw_choice["enabled"] = value if value else not raw_choice["enabled"] def _generate_after_input(self) -> List[Tuple[str, str]]: """Virtual text displayed after the user input.""" @@ -584,6 +587,8 @@ def _on_text_changed(self, _) -> None: def _handle_toggle_choice(self, _) -> None: """Handle tab event, alter the `selected` state of the choice.""" + if not self._multiselect: + return current_selected_index = self.content_control.selection["index"] self.content_control.choices[current_selected_index][ "enabled" diff --git a/InquirerPy/prompts/list.py b/InquirerPy/prompts/list.py index d4311ba..b94ac54 100644 --- a/InquirerPy/prompts/list.py +++ b/InquirerPy/prompts/list.py @@ -292,6 +292,8 @@ def _get_prompt_message_with_cursor(self) -> List[Tuple[str, str]]: def _handle_toggle_choice(self, _) -> None: """Toggle the `enabled` status of the choice.""" + if not self._multiselect: + return self.content_control.selection["enabled"] = not self.content_control.selection[ "enabled" ] @@ -302,6 +304,8 @@ def _handle_toggle_all(self, _, value: bool = None) -> None: Args: value: Sepcify a value to toggle. """ + if not self._multiselect: + return for choice in self.content_control.choices: if isinstance(choice["value"], Separator): continue