Skip to content

Commit 016ddf0

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 aa23737 commit 016ddf0

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

tools/lint-hotkeys

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from zulipterminal.config.keys import (
1212
HELP_CATEGORIES,
1313
HELP_CONTEXTS,
1414
KEY_BINDINGS,
15+
PARENT_CONTEXTS,
1516
display_keys_for_command,
1617
)
1718

@@ -93,6 +94,7 @@ def lint_hotkeys_file() -> None:
9394
error_flag |= lint_help_groups("category")
9495
error_flag |= lint_help_groups("context")
9596
error_flag |= lint_help_text()
97+
error_flag |= lint_parent_contexts()
9698

9799
if error_flag:
98100
print(f"Rerun this command after resolving errors in config/{KEYS_FILE_NAME}")
@@ -178,6 +180,38 @@ def lint_help_groups(group: Group) -> bool:
178180
return error_flag
179181

180182

183+
def lint_parent_contexts() -> bool:
184+
"""
185+
Lint for any typos in the PARENT_CONTEXTS dict
186+
"""
187+
key_typos = []
188+
value_typos = []
189+
190+
for key, value_list in PARENT_CONTEXTS.items():
191+
if key not in HELP_CONTEXTS:
192+
key_typos.append(key)
193+
for value in value_list:
194+
if value not in HELP_CONTEXTS:
195+
value_typos.append(value)
196+
197+
error_message = ""
198+
if key_typos:
199+
error_message += (
200+
f"Invalid contexts in parent context keys: {', '.join(key_typos)}.\n"
201+
)
202+
if value_typos:
203+
error_message += (
204+
f"Invalid contexts in parent context values: {', '.join(value_typos)}.\n"
205+
)
206+
207+
if error_message:
208+
error_message += f" Choose a context from:\n{', '.join(HELP_CONTEXTS.keys())}\n"
209+
print(error_message)
210+
return True
211+
212+
return False
213+
214+
181215
def generate_hotkeys_file(group: Group) -> None:
182216
"""
183217
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
@@ -563,6 +563,24 @@ class KeyBinding(TypedDict):
563563
"search_box": "Search box",
564564
}
565565

566+
PARENT_CONTEXTS: Dict[str, List[str]] = {
567+
"global": [],
568+
"general": ["global"],
569+
"editor": ["global"],
570+
"compose_box": ["editor", "global"],
571+
"stream": ["general", "global", "button"],
572+
"topic": ["general", "global", "button"],
573+
"user": ["general", "global", "button"],
574+
"message": ["general", "global"],
575+
"stream_info": ["global", "popup"],
576+
"msg_info": ["global", "popup"],
577+
"emoji_list": ["global", "popup"],
578+
"about": ["global", "popup"],
579+
"search_box": ["global", "editor"],
580+
"popup": ["global"],
581+
"button": ["global"],
582+
}
583+
566584
ZT_TO_URWID_CMD_MAPPING = {
567585
"GO_UP": CURSOR_UP,
568586
"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,
@@ -1240,12 +1241,17 @@ def __init__(
12401241
self, controller: Any, title: str, context: Optional[str] = None
12411242
) -> None:
12421243
help_menu_content = []
1244+
if context:
1245+
valid_contexts = PARENT_CONTEXTS[context] + [context]
12431246
for category in HELP_CATEGORIES:
12441247
keys_in_category = (
12451248
binding
12461249
for binding in KEY_BINDINGS.values()
12471250
if binding["key_category"] == category
1248-
and (not context or context in binding["key_contexts"])
1251+
and (
1252+
not context
1253+
or bool(set(binding["key_contexts"]) & set(valid_contexts))
1254+
)
12491255
)
12501256
key_bindings = [
12511257
(

0 commit comments

Comments
 (0)