From f907c590c3b2da56ef13236bbc071a0402a66a44 Mon Sep 17 00:00:00 2001 From: ria02 Date: Tue, 12 Oct 2021 17:21:04 +1100 Subject: [PATCH 1/2] fix(fuzzy): toggle_all #18 --- InquirerPy/prompts/fuzzy.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/InquirerPy/prompts/fuzzy.py b/InquirerPy/prompts/fuzzy.py index 6919b13..6441d94 100644 --- a/InquirerPy/prompts/fuzzy.py +++ b/InquirerPy/prompts/fuzzy.py @@ -490,10 +490,11 @@ def _handle_toggle_all(self, _, value: bool = None) -> None: Args: value: Specify the value to toggle. """ - for choice in self.content_control.choices: - if isinstance(choice["value"], Separator): + 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.""" From a35ca26e73024c853a96ea75301866ce535dadd9 Mon Sep 17 00:00:00 2001 From: ria02 Date: Tue, 12 Oct 2021 18:22:01 +1100 Subject: [PATCH 2/2] fix: multiselect #25 --- InquirerPy/base/list.py | 14 +++++++------- InquirerPy/prompts/fuzzy.py | 6 +++++- InquirerPy/prompts/list.py | 4 ++++ 3 files changed, 16 insertions(+), 8 deletions(-) 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 6441d94..6940dbf 100644 --- a/InquirerPy/prompts/fuzzy.py +++ b/InquirerPy/prompts/fuzzy.py @@ -484,12 +484,14 @@ 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. """ + 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): @@ -585,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