Skip to content

Commit e79f68b

Browse files
committed
keys/views: Add mapping of contexts to broader contexts they belong to.
Update the contextual help menu to use the parent contexts as well. Add linting for parent contexts mapping.
1 parent 58b1a96 commit e79f68b

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

tools/lint-hotkeys

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from zulipterminal.config.keys import (
1111
HELP_CATEGORIES,
1212
HELP_CONTEXTS,
1313
KEY_BINDINGS,
14+
PARENT_CONTEXTS,
1415
display_keys_for_command,
1516
)
1617

@@ -90,7 +91,10 @@ def lint_hotkeys_file() -> None:
9091
error_flag = False
9192

9293
error_flag |= (
93-
lint_help_groups("category") | lint_help_groups("context") | lint_help_text()
94+
lint_help_groups("category")
95+
| lint_help_groups("context")
96+
| lint_help_text()
97+
| lint_parent_contexts()
9498
)
9599

96100
if error_flag:
@@ -182,6 +186,38 @@ def lint_help_groups(group: Group) -> bool:
182186
return error_flag
183187

184188

189+
def lint_parent_contexts() -> bool:
190+
"""
191+
Lint for any typos in the PARENT_CONTEXTS dict
192+
"""
193+
key_typos = []
194+
value_typos = []
195+
196+
for key, value_list in PARENT_CONTEXTS.items():
197+
if key not in HELP_CONTEXTS:
198+
key_typos.append(key)
199+
for value in value_list:
200+
if value not in HELP_CONTEXTS:
201+
value_typos.append(value)
202+
203+
error_message = ""
204+
if key_typos:
205+
error_message += (
206+
f"Invalid contexts in parent context keys: {', '.join(key_typos)}.\n"
207+
)
208+
if value_typos:
209+
error_message += (
210+
f"Invalid contexts in parent context values: {', '.join(value_typos)}.\n"
211+
)
212+
213+
if error_message:
214+
error_message += f" Choose a context from:\n{', '.join(HELP_CONTEXTS.keys())}\n"
215+
print(error_message)
216+
return True
217+
218+
return False
219+
220+
185221
def generate_hotkeys_file(group: Group) -> None:
186222
"""
187223
Generate output file based on help text description and

zulipterminal/config/keys.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,24 @@ class KeyBinding(TypedDict):
572572
"search_box": "Search box",
573573
}
574574

575+
PARENT_CONTEXTS: Dict[str, List[str]] = {
576+
"global": [],
577+
"general": ["global"],
578+
"editor": ["global"],
579+
"compose_box": ["editor", "global"],
580+
"stream": ["general", "global", "button"],
581+
"topic": ["general", "global", "button"],
582+
"user": ["general", "global", "button"],
583+
"message": ["general", "global"],
584+
"stream_info": ["global", "popup"],
585+
"msg_info": ["global", "popup"],
586+
"emoji_list": ["global", "popup"],
587+
"about": ["global", "popup"],
588+
"search_box": ["global", "editor"],
589+
"popup": ["global"],
590+
"button": ["global"],
591+
}
592+
575593
ZT_TO_URWID_CMD_MAPPING = {
576594
"GO_UP": CURSOR_UP,
577595
"GO_DOWN": CURSOR_DOWN,

zulipterminal/ui_tools/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from zulipterminal.config.keys import (
1515
HELP_CATEGORIES,
1616
KEY_BINDINGS,
17+
PARENT_CONTEXTS,
1718
display_key_for_urwid_key,
1819
display_keys_for_command,
1920
is_command_key,
@@ -1242,12 +1243,17 @@ def __init__(
12421243
self, controller: Any, title: str, context: Optional[str] = None
12431244
) -> None:
12441245
help_menu_content = []
1246+
if context:
1247+
valid_contexts = PARENT_CONTEXTS[context] + [context]
12451248
for category in HELP_CATEGORIES:
12461249
keys_in_category = (
12471250
binding
12481251
for binding in KEY_BINDINGS.values()
12491252
if binding["key_category"] == category
1250-
and (not context or context in binding["key_contexts"])
1253+
and (
1254+
not context
1255+
or bool(set(binding["key_contexts"]) & set(valid_contexts))
1256+
)
12511257
)
12521258
key_bindings = [
12531259
(

0 commit comments

Comments
 (0)