Skip to content

Commit 589c789

Browse files
Niloth-pneiljp
authored andcommitted
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 f61a435 commit 589c789

File tree

10 files changed

+43
-22
lines changed

10 files changed

+43
-22
lines changed

docs/hotkeys.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
|Scroll up|<kbd>PgUp</kbd> / <kbd>K</kbd>|
2626
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
2727
|Go to bottom / Last message|<kbd>End</kbd> / <kbd>G</kbd>|
28+
|Trigger the selected entry|<kbd>Enter</kbd>|
2829
|Narrow to all messages|<kbd>a</kbd> / <kbd>Esc</kbd>|
2930
|Narrow to all direct messages|<kbd>P</kbd>|
3031
|Narrow to all starred messages|<kbd>f</kbd>|
3132
|Narrow to messages in which you're mentioned|<kbd>#</kbd>|
3233
|Next unread topic|<kbd>n</kbd>|
3334
|Next unread direct message|<kbd>p</kbd>|
34-
|Perform current action|<kbd>Enter</kbd>|
3535

3636
## Searching
3737
|Command|Key Combination|
@@ -41,6 +41,7 @@
4141
|Search streams|<kbd>q</kbd>|
4242
|Search topics in a stream|<kbd>q</kbd>|
4343
|Search emojis from emoji picker|<kbd>p</kbd>|
44+
|Submit search and browse results|<kbd>Enter</kbd>|
4445

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

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

tests/ui_tools/test_boxes.py

+1-1
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

+2-2
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

+3-1
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ def test_init(self, edit_mode_view: EditModeView) -> None:
865865
(2, "change_all"),
866866
],
867867
)
868-
@pytest.mark.parametrize("key", keys_for_command("ENTER"))
868+
@pytest.mark.parametrize("key", keys_for_command("ACTIVATE_BUTTON"))
869869
def test_select_edit_mode(
870870
self,
871871
edit_mode_view: EditModeView,
@@ -1558,7 +1558,7 @@ def test_keypress_exit_popup(
15581558
self.stream_info_view.keypress(size, key)
15591559
assert self.controller.exit_popup.called
15601560

1561-
@pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
1561+
@pytest.mark.parametrize("key", (*keys_for_command("ACTIVATE_BUTTON"), " "))
15621562
def test_checkbox_toggle_mute_stream(
15631563
self, key: str, widget_size: Callable[[Widget], urwid_Size]
15641564
) -> None:
@@ -1571,7 +1571,7 @@ def test_checkbox_toggle_mute_stream(
15711571

15721572
toggle_mute_status.assert_called_once_with(stream_id)
15731573

1574-
@pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
1574+
@pytest.mark.parametrize("key", (*keys_for_command("ACTIVATE_BUTTON"), " "))
15751575
def test_checkbox_toggle_pin_stream(
15761576
self, key: str, widget_size: Callable[[Widget], urwid_Size]
15771577
) -> None:
@@ -1584,7 +1584,7 @@ def test_checkbox_toggle_pin_stream(
15841584

15851585
toggle_pin_status.assert_called_once_with(stream_id)
15861586

1587-
@pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
1587+
@pytest.mark.parametrize("key", (*keys_for_command("ACTIVATE_BUTTON"), " "))
15881588
def test_checkbox_toggle_visual_notification(
15891589
self, key: str, widget_size: Callable[[Widget], urwid_Size]
15901590
) -> None:

zulipterminal/config/keys.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class KeyBinding(TypedDict):
9696
'help_text': 'Go to bottom / Last message',
9797
'key_category': 'navigation',
9898
},
99+
'ACTIVATE_BUTTON': {
100+
'keys': ['enter'],
101+
'help_text': 'Trigger the selected entry',
102+
'key_category': 'navigation',
103+
},
99104
'REPLY_MESSAGE': {
100105
'keys': ['r', 'enter'],
101106
'help_text': 'Reply to the current message',
@@ -249,16 +254,16 @@ class KeyBinding(TypedDict):
249254
'excluded_from_random_tips': True,
250255
'key_category': 'searching',
251256
},
257+
'EXECUTE_SEARCH': {
258+
'keys': ['enter'],
259+
'help_text': 'Submit search and browse results',
260+
'key_category': 'searching',
261+
},
252262
'TOGGLE_MUTE_STREAM': {
253263
'keys': ['m'],
254264
'help_text': 'Mute/unmute streams',
255265
'key_category': 'stream_list',
256266
},
257-
'ENTER': {
258-
'keys': ['enter'],
259-
'help_text': 'Perform current action',
260-
'key_category': 'navigation',
261-
},
262267
'THUMBS_UP': {
263268
'keys': ['+'],
264269
'help_text': 'Toggle thumbs-up reaction to the current message',
@@ -405,6 +410,14 @@ class KeyBinding(TypedDict):
405410
'help_text': 'Swap with previous character',
406411
'key_category': 'editor_text_manipulation',
407412
},
413+
'NEW_LINE': {
414+
# urwid_readline's command
415+
# This obvious hotkey is added to clarify against 'enter' to send
416+
# and to differentiate from other hotkeys using 'enter'.
417+
'keys': ['enter'],
418+
'help_text': 'Insert new line',
419+
'key_category': 'msg_compose',
420+
},
408421
'FULL_RENDERED_MESSAGE': {
409422
'keys': ['f'],
410423
'help_text': 'Show/hide full rendered message (from message information)',

zulipterminal/ui_tools/boxes.py

+4-4
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

+2-2
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

+1-1
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

+5-1
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,11 @@ def __init__(self, controller: Any, button: Any) -> None:
17581758
for mode in EDIT_MODE_CAPTIONS:
17591759
self.add_radio_button(mode)
17601760
super().__init__(
1761-
controller, self.widgets, "ENTER", 62, "Topic edit propagation mode"
1761+
controller,
1762+
self.widgets,
1763+
"ACTIVATE_BUTTON",
1764+
62,
1765+
"Topic edit propagation mode",
17621766
)
17631767
# Set cursor to marked checkbox.
17641768
for i in range(len(self.widgets)):

0 commit comments

Comments
 (0)