Skip to content

Commit

Permalink
fix: multiselect #25
Browse files Browse the repository at this point in the history
  • Loading branch information
ria02 committed Oct 12, 2021
1 parent f907c59 commit a35ca26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 7 additions & 7 deletions InquirerPy/base/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion InquirerPy/prompts/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions InquirerPy/prompts/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand All @@ -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
Expand Down

0 comments on commit a35ca26

Please sign in to comment.