Skip to content

Commit 00da8d4

Browse files
committed
keys: Made edits on review feedback. To be squashed.
- Assigned ACTIVATE_BUTTON to category "navigation". - Placed it at the bottom of the UI navigation hotkeys. - Connected the key binding to urwid's command map. - Added space hotkey to the key binding. Added comment explaining the motivation behind NEW_LINE. Updated tests. Hotkeys document regenerated.
1 parent 64f5c89 commit 00da8d4

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

docs/hotkeys.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
## General
66
|Command|Key Combination|
77
| :--- | :---: |
8-
|Trigger the selected entry|<kbd>Enter</kbd>|
98
|Show/hide Help Menu|<kbd>?</kbd>|
109
|Show/hide Markdown Help Menu|<kbd>Meta</kbd> + <kbd>m</kbd>|
1110
|Show/hide About Menu|<kbd>Meta</kbd> + <kbd>?</kbd>|
@@ -25,6 +24,7 @@
2524
|Scroll up|<kbd>PgUp</kbd> / <kbd>K</kbd>|
2625
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
2726
|Go to bottom / Last message|<kbd>End</kbd> / <kbd>G</kbd>|
27+
|Trigger the selected entry|<kbd>Enter</kbd> / <kbd>Space</kbd>|
2828
|Narrow to all messages|<kbd>a</kbd> / <kbd>Esc</kbd>|
2929
|Narrow to all direct messages|<kbd>P</kbd>|
3030
|Narrow to all starred messages|<kbd>f</kbd>|

tests/ui_tools/test_messages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pytest import param as case
88
from urwid import Columns, Divider, Padding, Text
99

10-
from zulipterminal.config.keys import keys_for_command
10+
from zulipterminal.config.keys import keys_for_command, primary_key_for_command
1111
from zulipterminal.config.symbols import (
1212
ALL_MESSAGES_MARKER,
1313
DIRECT_MESSAGE_MARKER,
@@ -1968,6 +1968,7 @@ def test_footlinks_limit(self, maximum_footlinks, expected_instance):
19681968
def test_mouse_event_left_click(
19691969
self, mocker, msg_box, key, widget_size, compose_box_is_open
19701970
):
1971+
expected_keypress = primary_key_for_command("ACTIVATE_BUTTON")
19711972
size = widget_size(msg_box)
19721973
col = 1
19731974
row = 1
@@ -1981,4 +1982,4 @@ def test_mouse_event_left_click(
19811982
if compose_box_is_open:
19821983
msg_box.keypress.assert_not_called()
19831984
else:
1984-
msg_box.keypress.assert_called_once_with(size, key)
1985+
msg_box.keypress.assert_called_once_with(size, expected_keypress)

zulipterminal/config/keys.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from typing_extensions import NotRequired, TypedDict
88
from urwid.command_map import (
9+
ACTIVATE,
910
CURSOR_DOWN,
1011
CURSOR_LEFT,
1112
CURSOR_MAX_RIGHT,
@@ -29,11 +30,6 @@ class KeyBinding(TypedDict):
2930
# Key that is displayed in the UI is determined by the method
3031
# primary_key_for_command. (Currently the first key in the list)
3132

32-
'ACTIVATE_BUTTON': {
33-
'keys': ['enter'],
34-
'help_text': 'Trigger the selected entry',
35-
'key_category': 'general',
36-
},
3733
'HELP': {
3834
'keys': ['?'],
3935
'help_text': 'Show/hide Help Menu',
@@ -96,6 +92,11 @@ class KeyBinding(TypedDict):
9692
'help_text': 'Go to bottom / Last message',
9793
'key_category': 'navigation',
9894
},
95+
'ACTIVATE_BUTTON': {
96+
'keys': ['enter', ' '],
97+
'help_text': 'Trigger the selected entry',
98+
'key_category': 'navigation',
99+
},
99100
'REPLY_MESSAGE': {
100101
'keys': ['r', 'enter'],
101102
'help_text': 'Reply to the current message',
@@ -406,6 +407,9 @@ class KeyBinding(TypedDict):
406407
'key_category': 'editor_text_manipulation',
407408
},
408409
'NEW_LINE': {
410+
# urwid_readline's command
411+
# This obvious hotkey is added to clarify against 'enter' to send
412+
# and to differentiate from other hotkeys using 'enter'.
409413
'keys': ['enter'],
410414
'help_text': 'Insert new line',
411415
'key_category': 'msg_compose',
@@ -442,6 +446,7 @@ class KeyBinding(TypedDict):
442446
"SCROLL_UP": CURSOR_PAGE_UP,
443447
"SCROLL_DOWN": CURSOR_PAGE_DOWN,
444448
"GO_TO_BOTTOM": CURSOR_MAX_RIGHT,
449+
"ACTIVATE_BUTTON": ACTIVATE,
445450
}
446451

447452

@@ -487,6 +492,9 @@ def display_key_for_urwid_key(urwid_key: str) -> str:
487492
"""
488493
Returns a displayable user-centric format of the urwid key.
489494
"""
495+
if urwid_key == " ":
496+
return "Space"
497+
490498
for urwid_map_key, display_map_key in URWID_KEY_TO_DISPLAY_KEY_MAPPING.items():
491499
if urwid_map_key in urwid_key:
492500
urwid_key = urwid_key.replace(urwid_map_key, display_map_key)

0 commit comments

Comments
 (0)