Skip to content

Commit 522339a

Browse files
committed
keys/ui_tools: Break down the generalized ENTER command.
Breaks down the ENTER command into more specific commands. - ACTIVATE_BUTTON - EXECUTE_SEARCH - NEW_LINE Tests and docs updated.
1 parent e5e9010 commit 522339a

File tree

10 files changed

+43
-22
lines changed

10 files changed

+43
-22
lines changed

docs/hotkeys.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
|Scroll up|<kbd>PgUp</kbd> / <kbd>K</kbd>|
2525
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
2626
|Go to bottom / Last message|<kbd>End</kbd> / <kbd>G</kbd>|
27+
|Trigger the selected entry|<kbd>Enter</kbd>|
2728
|Narrow to all messages|<kbd>a</kbd> / <kbd>Esc</kbd>|
2829
|Narrow to all direct messages|<kbd>P</kbd>|
2930
|Narrow to all starred messages|<kbd>f</kbd>|
3031
|Narrow to messages in which you're mentioned|<kbd>#</kbd>|
3132
|Next unread topic|<kbd>n</kbd>|
3233
|Next unread direct message|<kbd>p</kbd>|
33-
|Perform current action|<kbd>Enter</kbd>|
3434

3535
## Searching
3636
|Command|Key Combination|
@@ -40,6 +40,7 @@
4040
|Search streams|<kbd>q</kbd>|
4141
|Search topics in a stream|<kbd>q</kbd>|
4242
|Search emojis from emoji picker|<kbd>p</kbd>|
43+
|Execute the search and go to search results|<kbd>Enter</kbd>|
4344

4445
## Message actions
4546
|Command|Key Combination|
@@ -83,6 +84,7 @@
8384
|Autocomplete @mentions, #stream_names, :emoji: and topics|<kbd>Ctrl</kbd> + <kbd>f</kbd>|
8485
|Cycle through autocomplete suggestions in reverse|<kbd>Ctrl</kbd> + <kbd>r</kbd>|
8586
|Narrow to compose box message recipient|<kbd>Meta</kbd> + <kbd>.</kbd>|
87+
|Insert new line|<kbd>Enter</kbd>|
8688

8789
## Editor: Navigation
8890
|Command|Key Combination|

tests/ui_tools/test_boxes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ def test_valid_char(
18191819
@pytest.mark.parametrize(
18201820
"log, expect_body_focus_set", [([], False), (["SOMETHING"], True)]
18211821
)
1822-
@pytest.mark.parametrize("enter_key", keys_for_command("ENTER"))
1822+
@pytest.mark.parametrize("enter_key", keys_for_command("EXECUTE_SEARCH"))
18231823
def test_keypress_ENTER(
18241824
self,
18251825
panel_search_box: PanelSearchBox,

tests/ui_tools/test_buttons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_keypress_TOGGLE_MUTE_STREAM(
262262

263263
class TestUserButton:
264264
# FIXME Place this in a general test of a derived class?
265-
@pytest.mark.parametrize("enter_key", keys_for_command("ENTER"))
265+
@pytest.mark.parametrize("enter_key", keys_for_command("ACTIVATE_BUTTON"))
266266
def test_activate_called_once_on_keypress(
267267
self,
268268
mocker: MockerFixture,
@@ -358,7 +358,7 @@ def test_init_calls_top_button(
358358
assert emoji_button.emoji_name == emoji_unit[0]
359359
assert emoji_button.reaction_count == count
360360

361-
@pytest.mark.parametrize("key", keys_for_command("ENTER"))
361+
@pytest.mark.parametrize("key", keys_for_command("ACTIVATE_BUTTON"))
362362
@pytest.mark.parametrize(
363363
"emoji, has_user_reacted, is_selected_final, expected_reaction_count",
364364
[

tests/ui_tools/test_messages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,9 @@ def test_footlinks_limit(self, maximum_footlinks, expected_instance):
19611961
assert isinstance(footlinks, expected_instance)
19621962

19631963
@pytest.mark.parametrize(
1964-
"key", keys_for_command("ENTER"), ids=lambda param: f"left_click-key:{param}"
1964+
"key",
1965+
keys_for_command("ACTIVATE_BUTTON"),
1966+
ids=lambda param: f"left_click-key:{param}",
19651967
)
19661968
def test_mouse_event_left_click(
19671969
self, mocker, msg_box, key, widget_size, compose_box_is_open

tests/ui_tools/test_popups.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ def test_init(self, edit_mode_view: EditModeView) -> None:
830830
(2, "change_all"),
831831
],
832832
)
833-
@pytest.mark.parametrize("key", keys_for_command("ENTER"))
833+
@pytest.mark.parametrize("key", keys_for_command("ACTIVATE_BUTTON"))
834834
def test_select_edit_mode(
835835
self,
836836
edit_mode_view: EditModeView,
@@ -1523,7 +1523,7 @@ def test_keypress_exit_popup(
15231523
self.stream_info_view.keypress(size, key)
15241524
assert self.controller.exit_popup.called
15251525

1526-
@pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
1526+
@pytest.mark.parametrize("key", (*keys_for_command("ACTIVATE_BUTTON"), " "))
15271527
def test_checkbox_toggle_mute_stream(
15281528
self, key: str, widget_size: Callable[[Widget], urwid_Size]
15291529
) -> None:
@@ -1536,7 +1536,7 @@ def test_checkbox_toggle_mute_stream(
15361536

15371537
toggle_mute_status.assert_called_once_with(stream_id)
15381538

1539-
@pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
1539+
@pytest.mark.parametrize("key", (*keys_for_command("ACTIVATE_BUTTON"), " "))
15401540
def test_checkbox_toggle_pin_stream(
15411541
self, key: str, widget_size: Callable[[Widget], urwid_Size]
15421542
) -> None:
@@ -1549,7 +1549,7 @@ def test_checkbox_toggle_pin_stream(
15491549

15501550
toggle_pin_status.assert_called_once_with(stream_id)
15511551

1552-
@pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
1552+
@pytest.mark.parametrize("key", (*keys_for_command("ACTIVATE_BUTTON"), " "))
15531553
def test_checkbox_toggle_visual_notification(
15541554
self, key: str, widget_size: Callable[[Widget], urwid_Size]
15551555
) -> None:

zulipterminal/config/keys.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class KeyBinding(TypedDict):
9191
'help_text': 'Go to bottom / Last message',
9292
'key_category': 'navigation',
9393
},
94+
'ACTIVATE_BUTTON': {
95+
'keys': ['enter'],
96+
'help_text': 'Trigger the selected entry',
97+
'key_category': 'navigation',
98+
},
9499
'REPLY_MESSAGE': {
95100
'keys': ['r', 'enter'],
96101
'help_text': 'Reply to the current message',
@@ -244,16 +249,16 @@ class KeyBinding(TypedDict):
244249
'excluded_from_random_tips': True,
245250
'key_category': 'searching',
246251
},
252+
'EXECUTE_SEARCH': {
253+
'keys': ['enter'],
254+
'help_text': 'Execute the search and go to search results',
255+
'key_category': 'searching',
256+
},
247257
'TOGGLE_MUTE_STREAM': {
248258
'keys': ['m'],
249259
'help_text': 'Mute/unmute streams',
250260
'key_category': 'stream_list',
251261
},
252-
'ENTER': {
253-
'keys': ['enter'],
254-
'help_text': 'Perform current action',
255-
'key_category': 'navigation',
256-
},
257262
'THUMBS_UP': {
258263
'keys': ['+'],
259264
'help_text': 'Toggle thumbs-up reaction to the current message',
@@ -400,6 +405,14 @@ class KeyBinding(TypedDict):
400405
'help_text': 'Swap with previous character',
401406
'key_category': 'editor_text_manipulation',
402407
},
408+
'NEW_LINE': {
409+
# urwid_readline's command
410+
# This obvious hotkey is added to clarify against 'enter' to send
411+
# and to differentiate from other hotkeys using 'enter'.
412+
'keys': ['enter'],
413+
'help_text': 'Insert new line',
414+
'key_category': 'msg_compose',
415+
},
403416
'FULL_RENDERED_MESSAGE': {
404417
'keys': ['f'],
405418
'help_text': 'Show/hide full rendered message (from message information)',

zulipterminal/ui_tools/boxes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,14 +947,14 @@ def main_view(self) -> Any:
947947

948948
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
949949
if (
950-
is_command_key("ENTER", key) and self.text_box.edit_text == ""
950+
is_command_key("EXECUTE_SEARCH", key) and self.text_box.edit_text == ""
951951
) or is_command_key("GO_BACK", key):
952952
self.text_box.set_edit_text("")
953953
self.controller.exit_editor_mode()
954954
self.controller.view.middle_column.set_focus("body")
955955
return key
956956

957-
elif is_command_key("ENTER", key):
957+
elif is_command_key("EXECUTE_SEARCH", key):
958958
self.controller.exit_editor_mode()
959959
self.controller.search_messages(self.text_box.edit_text)
960960
self.controller.view.middle_column.set_focus("body")
@@ -1003,15 +1003,15 @@ def valid_char(self, ch: str) -> bool:
10031003

10041004
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
10051005
if (
1006-
is_command_key("ENTER", key) and self.get_edit_text() == ""
1006+
is_command_key("EXECUTE_SEARCH", key) and self.get_edit_text() == ""
10071007
) or is_command_key("GO_BACK", key):
10081008
self.panel_view.view.controller.exit_editor_mode()
10091009
self.reset_search_text()
10101010
self.panel_view.set_focus("body")
10111011
# Don't call 'Esc' when inside a popup search-box.
10121012
if not self.panel_view.view.controller.is_any_popup_open():
10131013
self.panel_view.keypress(size, primary_key_for_command("GO_BACK"))
1014-
elif is_command_key("ENTER", key) and not self.panel_view.empty_search:
1014+
elif is_command_key("EXECUTE_SEARCH", key) and not self.panel_view.empty_search:
10151015
self.panel_view.view.controller.exit_editor_mode()
10161016
self.set_caption([("filter_results", " Search Results "), " "])
10171017
self.panel_view.set_focus("body")

zulipterminal/ui_tools/buttons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def activate(self, key: Any) -> None:
120120
self.show_function()
121121

122122
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
123-
if is_command_key("ENTER", key):
123+
if is_command_key("ACTIVATE_BUTTON", key):
124124
self.activate(key)
125125
return None
126126
else: # This is in the else clause, to avoid multiple activation
@@ -417,7 +417,7 @@ def mouse_event(
417417
self, size: urwid_Size, event: str, button: int, col: int, row: int, focus: int
418418
) -> bool:
419419
if event == "mouse press" and button == 1:
420-
self.keypress(size, primary_key_for_command("ENTER"))
420+
self.keypress(size, primary_key_for_command("ACTIVATE_BUTTON"))
421421
return True
422422
return super().mouse_event(size, event, button, col, row, focus)
423423

zulipterminal/ui_tools/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def mouse_event(
898898
if event == "mouse press" and button == 1:
899899
if self.model.controller.is_in_editor_mode():
900900
return True
901-
self.keypress(size, primary_key_for_command("ENTER"))
901+
self.keypress(size, primary_key_for_command("ACTIVATE_BUTTON"))
902902
return True
903903

904904
return super().mouse_event(size, event, button, col, row, focus)

zulipterminal/ui_tools/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,11 @@ def __init__(self, controller: Any, button: Any) -> None:
17401740
for mode in EDIT_MODE_CAPTIONS:
17411741
self.add_radio_button(mode)
17421742
super().__init__(
1743-
controller, self.widgets, "ENTER", 62, "Topic edit propagation mode"
1743+
controller,
1744+
self.widgets,
1745+
"ACTIVATE_BUTTON",
1746+
62,
1747+
"Topic edit propagation mode",
17441748
)
17451749
# Set cursor to marked checkbox.
17461750
for i in range(len(self.widgets)):

0 commit comments

Comments
 (0)