diff --git a/tests/config/test_keys.py b/tests/config/test_keys.py index 752e69af29..06b505614c 100644 --- a/tests/config/test_keys.py +++ b/tests/config/test_keys.py @@ -75,24 +75,24 @@ def test_commands_for_random_tips(mocker: MockerFixture) -> None: "ALPHA": { "keys": ["a"], "help_text": "alpha", - "key_category": "category 1", + "key_categories": ["category 1"], "excluded_from_random_tips": True, }, "BETA": { "keys": ["b"], "help_text": "beta", - "key_category": "category 1", + "key_categories": ["category 1", "category 2"], "excluded_from_random_tips": False, }, "GAMMA": { "keys": ["g"], "help_text": "gamma", - "key_category": "category 1", + "key_categories": ["category 1"], }, "DELTA": { "keys": ["d"], "help_text": "delta", - "key_category": "category 2", + "key_categories": ["category 2"], "excluded_from_random_tips": True, }, } diff --git a/tools/lint-hotkeys b/tools/lint-hotkeys index 503a024e98..0d3b4e8f77 100755 --- a/tools/lint-hotkeys +++ b/tools/lint-hotkeys @@ -136,9 +136,10 @@ def read_help_categories() -> Dict[str, List[Tuple[str, List[str]]]]: """ categories = defaultdict(list) for cmd, item in KEY_BINDINGS.items(): - categories[item["key_category"]].append( - (item["help_text"], display_keys_for_command(cmd)) - ) + for category in item["key_categories"]: + categories[category].append( + (item["help_text"], display_keys_for_command(cmd)) + ) return categories diff --git a/zulipterminal/config/keys.py b/zulipterminal/config/keys.py index 473d19c0f9..ba18dc6e4e 100644 --- a/zulipterminal/config/keys.py +++ b/zulipterminal/config/keys.py @@ -21,7 +21,7 @@ class KeyBinding(TypedDict): keys: List[str] help_text: str excluded_from_random_tips: NotRequired[bool] - key_category: str + key_categories: List[str] # fmt: off @@ -33,382 +33,382 @@ class KeyBinding(TypedDict): 'keys': ['?'], 'help_text': 'Show/hide Help Menu', 'excluded_from_random_tips': True, - 'key_category': 'general', + 'key_categories': ['general'], }, 'MARKDOWN_HELP': { 'keys': ['meta m'], 'help_text': 'Show/hide Markdown Help Menu', - 'key_category': 'general', + 'key_categories': ['general'], }, 'ABOUT': { 'keys': ['meta ?'], 'help_text': 'Show/hide About Menu', - 'key_category': 'general', + 'key_categories': ['general'], }, 'GO_BACK': { 'keys': ['esc'], 'help_text': 'Go back', 'excluded_from_random_tips': False, - 'key_category': 'general', + 'key_categories': ['general'], }, 'OPEN_DRAFT': { 'keys': ['d'], 'help_text': 'Open draft message saved in this session', - 'key_category': 'general', + 'key_categories': ['general'], }, 'GO_UP': { 'keys': ['up', 'k'], 'help_text': 'Go up / Previous message', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'GO_DOWN': { 'keys': ['down', 'j'], 'help_text': 'Go down / Next message', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'GO_LEFT': { 'keys': ['left', 'h'], 'help_text': 'Go left', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'GO_RIGHT': { 'keys': ['right', 'l'], 'help_text': 'Go right', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'SCROLL_UP': { 'keys': ['page up', 'K'], 'help_text': 'Scroll up', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'SCROLL_DOWN': { 'keys': ['page down', 'J'], 'help_text': 'Scroll down', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'GO_TO_BOTTOM': { 'keys': ['end', 'G'], 'help_text': 'Go to bottom / Last message', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'REPLY_MESSAGE': { 'keys': ['r', 'enter'], 'help_text': 'Reply to the current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'MENTION_REPLY': { 'keys': ['@'], 'help_text': 'Reply mentioning the sender of the current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'QUOTE_REPLY': { 'keys': ['>'], 'help_text': 'Reply quoting the current message text', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'REPLY_AUTHOR': { 'keys': ['R'], 'help_text': 'Reply directly to the sender of the current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'EDIT_MESSAGE': { 'keys': ['e'], 'help_text': "Edit message's content or topic", - 'key_category': 'msg_actions' + 'key_categories': ['msg_actions'], }, 'STREAM_MESSAGE': { 'keys': ['c'], 'help_text': 'New message to a stream', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'PRIVATE_MESSAGE': { 'keys': ['x'], 'help_text': 'New message to a person or group of people', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'CYCLE_COMPOSE_FOCUS': { 'keys': ['tab'], 'help_text': 'Cycle through recipient and content boxes', - 'key_category': 'msg_compose', + 'key_categories': ['msg_compose'], }, 'SEND_MESSAGE': { 'keys': ['ctrl d', 'meta enter'], 'help_text': 'Send a message', - 'key_category': 'msg_compose', + 'key_categories': ['msg_compose'], }, 'SAVE_AS_DRAFT': { 'keys': ['meta s'], 'help_text': 'Save current message as a draft', - 'key_category': 'msg_compose', + 'key_categories': ['msg_compose'], }, 'AUTOCOMPLETE': { 'keys': ['ctrl f'], 'help_text': ('Autocomplete @mentions, #stream_names, :emoji:' ' and topics'), - 'key_category': 'msg_compose', + 'key_categories': ['msg_compose'], }, 'AUTOCOMPLETE_REVERSE': { 'keys': ['ctrl r'], 'help_text': 'Cycle through autocomplete suggestions in reverse', - 'key_category': 'msg_compose', + 'key_categories': ['msg_compose'], }, 'ADD_REACTION': { 'keys': [':'], 'help_text': 'Show/hide emoji picker for current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'STREAM_NARROW': { 'keys': ['s'], 'help_text': 'Narrow to the stream of the current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'TOPIC_NARROW': { 'keys': ['S'], 'help_text': 'Narrow to the topic of the current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'NARROW_MESSAGE_RECIPIENT': { 'keys': ['meta .'], 'help_text': 'Narrow to compose box message recipient', - 'key_category': 'msg_compose', + 'key_categories': ['msg_compose'], }, 'TOGGLE_NARROW': { 'keys': ['z'], 'help_text': 'Narrow to a topic/direct-chat, or stream/all-direct-messages', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'REACTION_AGREEMENT': { 'keys': ['='], 'help_text': 'Toggle first emoji reaction on selected message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'TOGGLE_TOPIC': { 'keys': ['t'], 'help_text': 'Toggle topics in a stream', - 'key_category': 'stream_list', + 'key_categories': ['stream_list'], }, 'ALL_MESSAGES': { 'keys': ['a', 'esc'], 'help_text': 'Narrow to all messages', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'ALL_PM': { 'keys': ['P'], 'help_text': 'Narrow to all direct messages', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'ALL_STARRED': { 'keys': ['f'], 'help_text': 'Narrow to all starred messages', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'ALL_MENTIONS': { 'keys': ['#'], 'help_text': "Narrow to messages in which you're mentioned", - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'NEXT_UNREAD_TOPIC': { 'keys': ['n'], 'help_text': 'Next unread topic', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'NEXT_UNREAD_PM': { 'keys': ['p'], 'help_text': 'Next unread direct message', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'SEARCH_PEOPLE': { 'keys': ['w'], 'help_text': 'Search users', - 'key_category': 'searching', + 'key_categories': ['searching'], }, 'SEARCH_MESSAGES': { 'keys': ['/'], 'help_text': 'Search messages', - 'key_category': 'searching', + 'key_categories': ['searching'], }, 'SEARCH_STREAMS': { 'keys': ['q'], 'help_text': 'Search streams', - 'key_category': 'searching', + 'key_categories': ['searching'], }, 'SEARCH_TOPICS': { 'keys': ['q'], 'help_text': 'Search topics in a stream', - 'key_category': 'searching', + 'key_categories': ['searching'], }, 'SEARCH_EMOJIS': { 'keys': ['p'], 'help_text': 'Search emojis from emoji picker', 'excluded_from_random_tips': True, - 'key_category': 'searching', + 'key_categories': ['searching'], }, 'TOGGLE_MUTE_STREAM': { 'keys': ['m'], 'help_text': 'Mute/unmute streams', - 'key_category': 'stream_list', + 'key_categories': ['stream_list'], }, 'ENTER': { 'keys': ['enter'], 'help_text': 'Perform current action', - 'key_category': 'navigation', + 'key_categories': ['navigation'], }, 'THUMBS_UP': { 'keys': ['+'], 'help_text': 'Toggle thumbs-up reaction to the current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'TOGGLE_STAR_STATUS': { 'keys': ['ctrl s', '*'], 'help_text': 'Toggle star status of the current message', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'MSG_INFO': { 'keys': ['i'], 'help_text': 'Show/hide message information', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'MSG_SENDER_INFO': { 'keys': ['u'], 'help_text': 'Show/hide message sender information', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'EDIT_HISTORY': { 'keys': ['e'], 'help_text': 'Show/hide edit history (from message information)', 'excluded_from_random_tips': True, - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'VIEW_IN_BROWSER': { 'keys': ['v'], 'help_text': 'View current message in browser (from message information)', 'excluded_from_random_tips': True, - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'STREAM_INFO': { 'keys': ['i'], 'help_text': 'Show/hide stream information & modify settings', - 'key_category': 'stream_list', + 'key_categories': ['stream_list'], }, 'STREAM_MEMBERS': { 'keys': ['m'], 'help_text': 'Show/hide stream members (from stream information)', 'excluded_from_random_tips': True, - 'key_category': 'stream_list', + 'key_categories': ['stream_list'], }, 'COPY_STREAM_EMAIL': { 'keys': ['c'], 'help_text': 'Copy stream email to clipboard (from stream information)', 'excluded_from_random_tips': True, - 'key_category': 'stream_list', + 'key_categories': ['stream_list'], }, 'REDRAW': { 'keys': ['ctrl l'], 'help_text': 'Redraw screen', - 'key_category': 'general', + 'key_categories': ['general'], }, 'QUIT': { 'keys': ['ctrl c'], 'help_text': 'Quit', - 'key_category': 'general', + 'key_categories': ['general'], }, 'USER_INFO': { 'keys': ['i'], 'help_text': 'Show/hide user information (from users list)', - 'key_category': 'general', + 'key_categories': ['general'], }, 'BEGINNING_OF_LINE': { 'keys': ['ctrl a', 'home'], 'help_text': 'Start of line', - 'key_category': 'editor_navigation', + 'key_categories': ['editor_navigation'], }, 'END_OF_LINE': { 'keys': ['ctrl e', 'end'], 'help_text': 'End of line', - 'key_category': 'editor_navigation', + 'key_categories': ['editor_navigation'], }, 'ONE_WORD_BACKWARD': { 'keys': ['meta b', 'shift left'], 'help_text': 'Start of current or previous word', - 'key_category': 'editor_navigation', + 'key_categories': ['editor_navigation'], }, 'ONE_WORD_FORWARD': { 'keys': ['meta f', 'shift right'], 'help_text': 'Start of next word', - 'key_category': 'editor_navigation', + 'key_categories': ['editor_navigation'], }, 'PREV_LINE': { 'keys': ['up', 'ctrl p'], 'help_text': 'Previous line', - 'key_category': 'editor_navigation', + 'key_categories': ['editor_navigation'], }, 'NEXT_LINE': { 'keys': ['down', 'ctrl n'], 'help_text': 'Next line', - 'key_category': 'editor_navigation', + 'key_categories': ['editor_navigation'], }, 'UNDO_LAST_ACTION': { 'keys': ['ctrl _'], 'help_text': 'Undo last action', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'CLEAR_MESSAGE': { 'keys': ['ctrl l'], 'help_text': 'Clear text box', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'CUT_TO_END_OF_LINE': { 'keys': ['ctrl k'], 'help_text': 'Cut forwards to the end of the line', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'CUT_TO_START_OF_LINE': { 'keys': ['ctrl u'], 'help_text': 'Cut backwards to the start of the line', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'CUT_TO_END_OF_WORD': { 'keys': ['meta d'], 'help_text': 'Cut forwards to the end of the current word', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'CUT_TO_START_OF_WORD': { 'keys': ['ctrl w', 'meta backspace'], 'help_text': 'Cut backwards to the start of the current word', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'CUT_WHOLE_LINE': { 'keys': ['meta x'], 'help_text': 'Cut the current line', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'PASTE_LAST_CUT': { 'keys': ['ctrl y'], 'help_text': 'Paste last cut section', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'DELETE_LAST_CHARACTER': { 'keys': ['ctrl h'], 'help_text': 'Delete previous character', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'TRANSPOSE_CHARACTERS': { 'keys': ['ctrl t'], 'help_text': 'Swap with previous character', - 'key_category': 'editor_text_manipulation', + 'key_categories': ['editor_text_manipulation'], }, 'FULL_RENDERED_MESSAGE': { 'keys': ['f'], 'help_text': 'Show/hide full rendered message (from message information)', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, 'FULL_RAW_MESSAGE': { 'keys': ['r'], 'help_text': 'Show/hide full raw message (from message information)', - 'key_category': 'msg_actions', + 'key_categories': ['msg_actions'], }, } # fmt: on diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index 30fcc42a49..25a577184b 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1224,7 +1224,7 @@ def __init__(self, controller: Any, title: str) -> None: keys_in_category = ( binding for binding in KEY_BINDINGS.values() - if binding["key_category"] == category + if category in binding["key_categories"] ) key_bindings = [ (