Skip to content

Commit

Permalink
keys: Add space key as an additional trigger of ACTIVATE_BUTTON command.
Browse files Browse the repository at this point in the history
For consistency with Urwid's ACTIVATE command.

Urwid's command map is updated to link Urwid's ACTIVATE with our
ACTIVATE_BUTTON command. Although they currently use the same keys,
they are synced to ensure future compatibility.

Hotkeys document regenerated.
Tests updated.
  • Loading branch information
Niloth-p authored and neiljp committed Jun 23, 2024
1 parent 589c789 commit 28d5f6a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|Scroll up|<kbd>PgUp</kbd> / <kbd>K</kbd>|
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
|Go to bottom / Last message|<kbd>End</kbd> / <kbd>G</kbd>|
|Trigger the selected entry|<kbd>Enter</kbd>|
|Trigger the selected entry|<kbd>Enter</kbd> / <kbd>Space</kbd>|
|Narrow to all messages|<kbd>a</kbd> / <kbd>Esc</kbd>|
|Narrow to all direct messages|<kbd>P</kbd>|
|Narrow to all starred messages|<kbd>f</kbd>|
Expand Down
5 changes: 3 additions & 2 deletions tests/ui_tools/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pytest import param as case
from urwid import Columns, Divider, Padding, Text

from zulipterminal.config.keys import keys_for_command
from zulipterminal.config.keys import keys_for_command, primary_key_for_command
from zulipterminal.config.symbols import (
ALL_MESSAGES_MARKER,
DIRECT_MESSAGE_MARKER,
Expand Down Expand Up @@ -1968,6 +1968,7 @@ def test_footlinks_limit(self, maximum_footlinks, expected_instance):
def test_mouse_event_left_click(
self, mocker, msg_box, key, widget_size, compose_box_is_open
):
expected_keypress = primary_key_for_command("ACTIVATE_BUTTON")
size = widget_size(msg_box)
col = 1
row = 1
Expand All @@ -1981,4 +1982,4 @@ def test_mouse_event_left_click(
if compose_box_is_open:
msg_box.keypress.assert_not_called()
else:
msg_box.keypress.assert_called_once_with(size, key)
msg_box.keypress.assert_called_once_with(size, expected_keypress)
7 changes: 6 additions & 1 deletion zulipterminal/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from typing_extensions import NotRequired, TypedDict
from urwid.command_map import (
ACTIVATE,
CURSOR_DOWN,
CURSOR_LEFT,
CURSOR_MAX_RIGHT,
Expand Down Expand Up @@ -97,7 +98,7 @@ class KeyBinding(TypedDict):
'key_category': 'navigation',
},
'ACTIVATE_BUTTON': {
'keys': ['enter'],
'keys': ['enter', ' '],
'help_text': 'Trigger the selected entry',
'key_category': 'navigation',
},
Expand Down Expand Up @@ -450,6 +451,7 @@ class KeyBinding(TypedDict):
"SCROLL_UP": CURSOR_PAGE_UP,
"SCROLL_DOWN": CURSOR_PAGE_DOWN,
"GO_TO_BOTTOM": CURSOR_MAX_RIGHT,
"ACTIVATE_BUTTON": ACTIVATE,
}


Expand Down Expand Up @@ -495,6 +497,9 @@ def display_key_for_urwid_key(urwid_key: str) -> str:
"""
Returns a displayable user-centric format of the urwid key.
"""
if urwid_key == " ":
return "Space"

for urwid_map_key, display_map_key in URWID_KEY_TO_DISPLAY_KEY_MAPPING.items():
if urwid_map_key in urwid_key:
urwid_key = urwid_key.replace(urwid_map_key, display_map_key)
Expand Down

0 comments on commit 28d5f6a

Please sign in to comment.