Skip to content

Commit be801c7

Browse files
preetmishraneiljp
authored andcommitted
views: Support 'j/k', 'J/K' and 'G/end' for navigation in the help menu.
This makes navigation more consistent throughout the user interface. Tests added for extra keypress options in HelpView. Fixes #517.
1 parent c0ca15f commit be801c7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/ui/test_ui_tools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,23 @@ def test_keypress_goback(self, key):
11011101
self.help_view.keypress(size, key)
11021102
assert self.controller.exit_popup.called
11031103

1104+
@pytest.mark.parametrize('key, expected_key', [
1105+
(key, expected_key)
1106+
for keys, expected_key in [
1107+
(keys_for_command('GO_UP'), 'up'),
1108+
(keys_for_command('GO_DOWN'), 'down'),
1109+
(keys_for_command('SCROLL_UP'), 'page up'),
1110+
(keys_for_command('SCROLL_DOWN'), 'page down'),
1111+
(keys_for_command('GO_TO_BOTTOM'), 'end'),
1112+
]
1113+
for key in keys
1114+
])
1115+
def test_keypress_navigation(self, mocker, key, expected_key):
1116+
size = (200, 20)
1117+
super_view = mocker.patch(VIEWS + '.urwid.ListBox.keypress')
1118+
self.help_view.keypress(size, key)
1119+
super_view.assert_called_once_with(size, expected_key)
1120+
11041121

11051122
class TestPopUpConfirmationView:
11061123
@pytest.fixture

zulipterminal/ui_tools/views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,16 @@ def __init__(self, controller: Any) -> None:
792792
def keypress(self, size: urwid_Size, key: str) -> str:
793793
if is_command_key('GO_BACK', key) or is_command_key('HELP', key):
794794
self.controller.exit_popup()
795+
elif is_command_key('GO_UP', key):
796+
key = 'up'
797+
elif is_command_key('GO_DOWN', key):
798+
key = 'down'
799+
elif is_command_key('SCROLL_UP', key):
800+
key = 'page up'
801+
elif is_command_key('SCROLL_DOWN', key):
802+
key = 'page down'
803+
elif is_command_key('GO_TO_BOTTOM', key):
804+
key = 'end'
795805
return super().keypress(size, key)
796806

797807

0 commit comments

Comments
 (0)