Skip to content

Commit d7b975c

Browse files
committed
refactor: keys/model/views: Extract EXIT_POPUP from GO_BACK command.
Added an exclusion in lint-hotkeys for `Esc` as both EXIT_POPUP and ALL_MESSAGES commands belong to the help category 'Navigation'. Tests updated. Hotkeys document regenerated.
1 parent 72920ad commit d7b975c

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

docs/hotkeys.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
## Navigation
1818
|Command|Key Combination|
1919
| :--- | :---: |
20+
|Close popup|<kbd>Esc</kbd>|
2021
|Go up / Previous message|<kbd>Up</kbd> / <kbd>k</kbd>|
2122
|Go down / Next message|<kbd>Down</kbd> / <kbd>j</kbd>|
2223
|Go left|<kbd>Left</kbd> / <kbd>h</kbd>|

tests/ui_tools/test_popups.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def test_exit_popup_no(
7878
self.callback.assert_not_called()
7979
assert self.controller.exit_popup.called
8080

81-
@pytest.mark.parametrize("key", keys_for_command("GO_BACK"))
82-
def test_exit_popup_GO_BACK(
81+
@pytest.mark.parametrize("key", keys_for_command("EXIT_POPUP"))
82+
def test_exit_popup_EXIT_POPUP(
8383
self,
8484
popup_view: PopUpConfirmationView,
8585
key: str,
@@ -133,8 +133,8 @@ def test_init(self, mocker: MockerFixture) -> None:
133133
self.pop_up_view.body, header=mocker.ANY, footer=mocker.ANY
134134
)
135135

136-
@pytest.mark.parametrize("key", keys_for_command("GO_BACK"))
137-
def test_keypress_GO_BACK(
136+
@pytest.mark.parametrize("key", keys_for_command("EXIT_POPUP"))
137+
def test_keypress_EXIT_POPUP(
138138
self,
139139
key: str,
140140
widget_size: Callable[[Widget], urwid_Size],
@@ -204,7 +204,7 @@ def mock_external_classes(self, mocker: MockerFixture) -> None:
204204
)
205205

206206
@pytest.mark.parametrize(
207-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("ABOUT")}
207+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("ABOUT")}
208208
)
209209
def test_keypress_exit_popup(
210210
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -432,7 +432,7 @@ def test__fetch_user_data_USER_NOT_FOUND(self, mocker: MockerFixture) -> None:
432432
assert custom_profile_data == {}
433433

434434
@pytest.mark.parametrize(
435-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("USER_INFO")}
435+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("USER_INFO")}
436436
)
437437
def test_keypress_exit_popup(
438438
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -505,7 +505,7 @@ def test_keypress_exit_popup_invalid_key(
505505
"key",
506506
{
507507
*keys_for_command("FULL_RENDERED_MESSAGE"),
508-
*keys_for_command("GO_BACK"),
508+
*keys_for_command("EXIT_POPUP"),
509509
},
510510
)
511511
def test_keypress_show_msg_info(
@@ -581,7 +581,7 @@ def test_keypress_exit_popup_invalid_key(
581581
"key",
582582
{
583583
*keys_for_command("FULL_RAW_MESSAGE"),
584-
*keys_for_command("GO_BACK"),
584+
*keys_for_command("EXIT_POPUP"),
585585
},
586586
)
587587
def test_keypress_show_msg_info(
@@ -653,7 +653,7 @@ def test_keypress_exit_popup_invalid_key(
653653
assert not self.controller.exit_popup.called
654654

655655
@pytest.mark.parametrize(
656-
"key", {*keys_for_command("EDIT_HISTORY"), *keys_for_command("GO_BACK")}
656+
"key", {*keys_for_command("EDIT_HISTORY"), *keys_for_command("EXIT_POPUP")}
657657
)
658658
def test_keypress_show_msg_info(
659659
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -876,7 +876,7 @@ def test_keypress_any_key(
876876
assert not self.controller.exit_popup.called
877877

878878
@pytest.mark.parametrize(
879-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("MARKDOWN_HELP")}
879+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("MARKDOWN_HELP")}
880880
)
881881
def test_keypress_exit_popup(
882882
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -907,7 +907,7 @@ def test_keypress_any_key(
907907
assert not self.controller.exit_popup.called
908908

909909
@pytest.mark.parametrize(
910-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("HELP")}
910+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("HELP")}
911911
)
912912
def test_keypress_exit_popup(
913913
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -1078,7 +1078,7 @@ def test_keypress_full_raw_message(
10781078
)
10791079

10801080
@pytest.mark.parametrize(
1081-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("MSG_INFO")}
1081+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("MSG_INFO")}
10821082
)
10831083
def test_keypress_exit_popup(
10841084
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -1514,7 +1514,7 @@ def test_footlinks(
15141514
assert footlinks_width == expected_footlinks_width
15151515

15161516
@pytest.mark.parametrize(
1517-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("STREAM_INFO")}
1517+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("STREAM_INFO")}
15181518
)
15191519
def test_keypress_exit_popup(
15201520
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -1579,7 +1579,7 @@ def mock_external_classes(self, mocker: MockerFixture) -> None:
15791579
self.stream_members_view = StreamMembersView(self.controller, stream_id)
15801580

15811581
@pytest.mark.parametrize(
1582-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("STREAM_MEMBERS")}
1582+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("STREAM_MEMBERS")}
15831583
)
15841584
def test_keypress_exit_popup(
15851585
self, key: str, widget_size: Callable[[Widget], urwid_Size]
@@ -1694,7 +1694,7 @@ def test_keypress_search_emoji(
16941694
assert self.emoji_picker_view.get_focus() == "header"
16951695

16961696
@pytest.mark.parametrize(
1697-
"key", {*keys_for_command("GO_BACK"), *keys_for_command("ADD_REACTION")}
1697+
"key", {*keys_for_command("EXIT_POPUP"), *keys_for_command("ADD_REACTION")}
16981698
)
16991699
def test_keypress_exit_called(
17001700
self, key: str, widget_size: Callable[[Widget], urwid_Size]

tools/lint-hotkeys

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SCRIPT_NAME = PurePath(__file__).name
2323
HELP_TEXT_STYLE = re.compile(r"^[a-zA-Z /()',&@#:_-]*$")
2424

2525
# Exclude keys from duplicate keys checking
26-
KEYS_TO_EXCLUDE = ["q", "e", "m", "r"]
26+
KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "Esc"]
2727

2828

2929
def main(fix: bool) -> None:

zulipterminal/config/keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class KeyBinding(TypedDict):
5656
'help_text': 'Open draft message saved in this session',
5757
'key_category': 'general',
5858
},
59+
'EXIT_POPUP': {
60+
'keys': ['esc'],
61+
'help_text': 'Close popup',
62+
'key_category': 'navigation',
63+
},
5964
'GO_UP': {
6065
'keys': ['up', 'k'],
6166
'help_text': 'Go up / Previous message',

zulipterminal/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ def _handle_message_event(self, event: Event) -> None:
16881688
"Press '{}' to close this window."
16891689
)
16901690
notice = notice_template.format(
1691-
failed_command, primary_display_key_for_command("GO_BACK")
1691+
failed_command, primary_display_key_for_command("EXIT_POPUP")
16921692
)
16931693
self.controller.popup_with_message(notice, width=50)
16941694
self.controller.update_screen()

zulipterminal/ui_tools/views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ def make_table_with_categories(
10581058
return widgets
10591059

10601060
def keypress(self, size: urwid_Size, key: str) -> str:
1061-
if is_command_key("GO_BACK", key) or is_command_key(self.command, key):
1061+
if is_command_key("EXIT_POPUP", key) or is_command_key(self.command, key):
10621062
self.controller.exit_popup()
10631063

10641064
return super().keypress(size, key)
@@ -1073,7 +1073,7 @@ def __init__(
10731073
urwid.Padding(urwid.Text(notice_text), left=1, right=1),
10741074
urwid.Divider(),
10751075
]
1076-
super().__init__(controller, widgets, "GO_BACK", width, title)
1076+
super().__init__(controller, widgets, "EXIT_POPUP", width, title)
10771077

10781078

10791079
class AboutView(PopUpView):
@@ -1333,7 +1333,7 @@ def exit_popup_no(self, args: Any) -> None:
13331333
self.controller.exit_popup()
13341334

13351335
def keypress(self, size: urwid_Size, key: str) -> str:
1336-
if is_command_key("GO_BACK", key):
1336+
if is_command_key("EXIT_POPUP", key):
13371337
self.controller.exit_popup()
13381338
return super().keypress(size, key)
13391339

@@ -1545,7 +1545,7 @@ def __init__(self, controller: Any, stream_id: int) -> None:
15451545
super().__init__(controller, widgets, "STREAM_INFO", popup_width, title)
15461546

15471547
def keypress(self, size: urwid_Size, key: str) -> str:
1548-
if is_command_key("GO_BACK", key) or is_command_key("STREAM_MEMBERS", key):
1548+
if is_command_key("EXIT_POPUP", key) or is_command_key("STREAM_MEMBERS", key):
15491549
self.controller.show_stream_info(stream_id=self.stream_id)
15501550
return key
15511551
return super().keypress(size, key)
@@ -1875,7 +1875,7 @@ def _get_author_prefix(snapshot: Dict[str, Any], tag: EditHistoryTag) -> str:
18751875
return author_prefix
18761876

18771877
def keypress(self, size: urwid_Size, key: str) -> str:
1878-
if is_command_key("GO_BACK", key) or is_command_key("EDIT_HISTORY", key):
1878+
if is_command_key("EXIT_POPUP", key) or is_command_key("EDIT_HISTORY", key):
18791879
self.controller.show_msg_info(
18801880
msg=self.message,
18811881
topic_links=self.topic_links,
@@ -1917,7 +1917,7 @@ def __init__(
19171917
)
19181918

19191919
def keypress(self, size: urwid_Size, key: str) -> str:
1920-
if is_command_key("GO_BACK", key) or is_command_key(
1920+
if is_command_key("EXIT_POPUP", key) or is_command_key(
19211921
"FULL_RENDERED_MESSAGE", key
19221922
):
19231923
self.controller.show_msg_info(
@@ -1969,7 +1969,7 @@ def __init__(
19691969
)
19701970

19711971
def keypress(self, size: urwid_Size, key: str) -> str:
1972-
if is_command_key("GO_BACK", key) or is_command_key("FULL_RAW_MESSAGE", key):
1972+
if is_command_key("EXIT_POPUP", key) or is_command_key("FULL_RAW_MESSAGE", key):
19731973
self.controller.show_msg_info(
19741974
msg=self.message,
19751975
topic_links=self.topic_links,
@@ -2124,7 +2124,7 @@ def keypress(self, size: urwid_Size, key: str) -> str:
21242124
self.emoji_search.set_caption(" ")
21252125
self.controller.enter_editor_mode_with(self.emoji_search)
21262126
return key
2127-
elif is_command_key("GO_BACK", key) or is_command_key("ADD_REACTION", key):
2127+
elif is_command_key("EXIT_POPUP", key) or is_command_key("ADD_REACTION", key):
21282128
for emoji_code, emoji_name in self.selected_emojis.items():
21292129
self.controller.model.toggle_message_reaction(self.message, emoji_name)
21302130
self.emoji_search.reset_search_text()

0 commit comments

Comments
 (0)