From 1b0d3741a8e29dd47d92a30595cbe88736cd30eb Mon Sep 17 00:00:00 2001 From: Niloth-p <20315308+Niloth-p@users.noreply.github.com> Date: Sat, 4 May 2024 18:10:15 +0530 Subject: [PATCH] views/keys: Add title-to-title scroll feature to Help Menu. Add 2 new commands to refocus to view the previous/next help category section. Hotkeys linting exclusion updated. Hotkeys document regenerated. --- docs/hotkeys.md | 2 ++ tools/lint-hotkeys | 2 +- zulipterminal/config/keys.py | 12 ++++++++++++ zulipterminal/ui_tools/views.py | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/hotkeys.md b/docs/hotkeys.md index 9454ccc538..1b7cf6c8ee 100644 --- a/docs/hotkeys.md +++ b/docs/hotkeys.md @@ -26,6 +26,8 @@ |Scroll down|PgDn / J| |Go to bottom / Last message|End / G| |Trigger the selected entry|Enter / Space| +|Go to previous help category|p| +|Go to next help category|n| ## Switching Messages View |Command|Key Combination| diff --git a/tools/lint-hotkeys b/tools/lint-hotkeys index 83a7db068e..004bf4635e 100755 --- a/tools/lint-hotkeys +++ b/tools/lint-hotkeys @@ -23,7 +23,7 @@ SCRIPT_NAME = PurePath(__file__).name HELP_TEXT_STYLE = re.compile(r"^[a-zA-Z /()',&@#:_-]*$") # Exclude keys from duplicate keys checking -KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "Esc"] +KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "Esc", "p", "n"] def main(fix: bool) -> None: diff --git a/zulipterminal/config/keys.py b/zulipterminal/config/keys.py index 6f84bf2369..12a61c7d5a 100644 --- a/zulipterminal/config/keys.py +++ b/zulipterminal/config/keys.py @@ -101,6 +101,18 @@ class KeyBinding(TypedDict): 'help_text': 'Trigger the selected entry', 'key_category': 'navigation', }, + 'GO_TO_PREVIOUS_TITLE': { + 'keys': ['p'], + 'help_text': 'Go to previous help category', + 'key_category': 'navigation', + 'excluded_from_random_tips': True, + }, + 'GO_TO_NEXT_TITLE': { + 'keys': ['n'], + 'help_text': 'Go to next help category', + 'key_category': 'navigation', + 'excluded_from_random_tips': True, + }, 'REPLY_MESSAGE': { 'keys': ['r', 'enter'], 'help_text': 'Reply to the current message', diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index c2034b3ef7..799fea68f1 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1261,6 +1261,33 @@ def __init__(self, controller: Any, title: str) -> None: super().__init__(controller, widgets, "HELP", popup_width, title) + self.category_start_positions = [ + index + for index, widget in enumerate(self.log) + if isinstance(widget, urwid.Text) + and widget.get_text()[1] + and widget.get_text()[1][0][0] == "popup_category" + ] + + def keypress(self, size: urwid_Size, key: str) -> str: + if is_command_key("GO_TO_NEXT_TITLE", key): + focus_position = self.log.get_focus()[1] + last_visible_position = focus_position + size[1] - 1 # type: ignore[misc] + last_help_entry = len(self.log) - 1 + if last_help_entry > last_visible_position: + for category_start_position in self.category_start_positions: + if category_start_position > focus_position: + self.log.set_focus(category_start_position) + break + + elif is_command_key("GO_TO_PREVIOUS_TITLE", key): + focus_position = self.log.get_focus()[1] + for category_start_position in reversed(self.category_start_positions): + if category_start_position < focus_position: + self.log.set_focus(category_start_position) + break + return super().keypress(size, key) + class MarkdownHelpView(PopUpView): def __init__(self, controller: Any, title: str) -> None: