Skip to content

Commit

Permalink
views/keys: Add title-to-title scroll feature to Help Menu.
Browse files Browse the repository at this point in the history
Add 2 new commands to refocus to view the previous/next help category
section.

Hotkeys linting exclusion updated.
Hotkeys document regenerated.
  • Loading branch information
Niloth-p committed Jun 28, 2024
1 parent d46b6d8 commit 4af72e4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
|Go to bottom / Last message|<kbd>End</kbd> / <kbd>G</kbd>|
|Trigger the selected entry|<kbd>Enter</kbd> / <kbd>Space</kbd>|
|Go to previous help category|<kbd>p</kbd>|
|Go to next help category|<kbd>n</kbd>|
|Narrow to all messages|<kbd>a</kbd> / <kbd>Esc</kbd>|
|Narrow to all direct messages|<kbd>P</kbd>|
|Narrow to all starred messages|<kbd>f</kbd>|
Expand Down
2 changes: 1 addition & 1 deletion tools/lint-hotkeys
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions zulipterminal/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
27 changes: 27 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4af72e4

Please sign in to comment.