Skip to content

Commit 1b0d374

Browse files
committed
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.
1 parent 66c74ba commit 1b0d374

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

docs/hotkeys.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
2727
|Go to bottom / Last message|<kbd>End</kbd> / <kbd>G</kbd>|
2828
|Trigger the selected entry|<kbd>Enter</kbd> / <kbd>Space</kbd>|
29+
|Go to previous help category|<kbd>p</kbd>|
30+
|Go to next help category|<kbd>n</kbd>|
2931

3032
## Switching Messages View
3133
|Command|Key Combination|

tools/lint-hotkeys

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SCRIPT_NAME = PurePath(__file__).name
2323
HELP_TEXT_STYLE = re.compile(r"^[a-zA-Z /()',&@#:_-]*$")
2424

2525
# Exclude keys from duplicate keys checking
26-
KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "Esc"]
26+
KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "Esc", "p", "n"]
2727

2828

2929
def main(fix: bool) -> None:

zulipterminal/config/keys.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ class KeyBinding(TypedDict):
101101
'help_text': 'Trigger the selected entry',
102102
'key_category': 'navigation',
103103
},
104+
'GO_TO_PREVIOUS_TITLE': {
105+
'keys': ['p'],
106+
'help_text': 'Go to previous help category',
107+
'key_category': 'navigation',
108+
'excluded_from_random_tips': True,
109+
},
110+
'GO_TO_NEXT_TITLE': {
111+
'keys': ['n'],
112+
'help_text': 'Go to next help category',
113+
'key_category': 'navigation',
114+
'excluded_from_random_tips': True,
115+
},
104116
'REPLY_MESSAGE': {
105117
'keys': ['r', 'enter'],
106118
'help_text': 'Reply to the current message',

zulipterminal/ui_tools/views.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,33 @@ def __init__(self, controller: Any, title: str) -> None:
12611261

12621262
super().__init__(controller, widgets, "HELP", popup_width, title)
12631263

1264+
self.category_start_positions = [
1265+
index
1266+
for index, widget in enumerate(self.log)
1267+
if isinstance(widget, urwid.Text)
1268+
and widget.get_text()[1]
1269+
and widget.get_text()[1][0][0] == "popup_category"
1270+
]
1271+
1272+
def keypress(self, size: urwid_Size, key: str) -> str:
1273+
if is_command_key("GO_TO_NEXT_TITLE", key):
1274+
focus_position = self.log.get_focus()[1]
1275+
last_visible_position = focus_position + size[1] - 1 # type: ignore[misc]
1276+
last_help_entry = len(self.log) - 1
1277+
if last_help_entry > last_visible_position:
1278+
for category_start_position in self.category_start_positions:
1279+
if category_start_position > focus_position:
1280+
self.log.set_focus(category_start_position)
1281+
break
1282+
1283+
elif is_command_key("GO_TO_PREVIOUS_TITLE", key):
1284+
focus_position = self.log.get_focus()[1]
1285+
for category_start_position in reversed(self.category_start_positions):
1286+
if category_start_position < focus_position:
1287+
self.log.set_focus(category_start_position)
1288+
break
1289+
return super().keypress(size, key)
1290+
12641291

12651292
class MarkdownHelpView(PopUpView):
12661293
def __init__(self, controller: Any, title: str) -> None:

0 commit comments

Comments
 (0)