Skip to content

Commit

Permalink
Merge pull request #26 from ria02/master
Browse files Browse the repository at this point in the history
Closes #18 #25
  • Loading branch information
kazhala authored Oct 12, 2021
2 parents e95dde5 + a35ca26 commit 4cafa1e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 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
13 changes: 9 additions & 4 deletions InquirerPy/prompts/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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"
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 4cafa1e

Please sign in to comment.