File tree Expand file tree Collapse file tree 3 files changed +62
-2
lines changed Expand file tree Collapse file tree 3 files changed +62
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ from zulipterminal.config.keys import (
11
11
HELP_CATEGORIES ,
12
12
HELP_CONTEXTS ,
13
13
KEY_BINDINGS ,
14
+ PARENT_CONTEXTS ,
14
15
display_keys_for_command ,
15
16
)
16
17
@@ -90,7 +91,10 @@ def lint_hotkeys_file() -> None:
90
91
error_flag = False
91
92
92
93
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 ()
94
98
)
95
99
96
100
if error_flag :
@@ -182,6 +186,38 @@ def lint_help_groups(group: Group) -> bool:
182
186
return error_flag
183
187
184
188
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
+
185
221
def generate_hotkeys_file (group : Group ) -> None :
186
222
"""
187
223
Generate output file based on help text description and
Original file line number Diff line number Diff line change @@ -572,6 +572,24 @@ class KeyBinding(TypedDict):
572
572
"search_box" : "Search box" ,
573
573
}
574
574
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
+
575
593
ZT_TO_URWID_CMD_MAPPING = {
576
594
"GO_UP" : CURSOR_UP ,
577
595
"GO_DOWN" : CURSOR_DOWN ,
Original file line number Diff line number Diff line change 14
14
from zulipterminal .config .keys import (
15
15
HELP_CATEGORIES ,
16
16
KEY_BINDINGS ,
17
+ PARENT_CONTEXTS ,
17
18
display_key_for_urwid_key ,
18
19
display_keys_for_command ,
19
20
is_command_key ,
@@ -1242,12 +1243,17 @@ def __init__(
1242
1243
self , controller : Any , title : str , context : Optional [str ] = None
1243
1244
) -> None :
1244
1245
help_menu_content = []
1246
+ if context :
1247
+ valid_contexts = PARENT_CONTEXTS [context ] + [context ]
1245
1248
for category in HELP_CATEGORIES :
1246
1249
keys_in_category = (
1247
1250
binding
1248
1251
for binding in KEY_BINDINGS .values ()
1249
1252
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
+ )
1251
1257
)
1252
1258
key_bindings = [
1253
1259
(
You can’t perform that action at this time.
0 commit comments