Skip to content

Commit 2a2ed8f

Browse files
committed
views: Support 'j/k', 'J/K' and 'G/end' for navigation in infoviews.
Extended support for navigation through the other specified keys in infoviews using PopUpView base class. Note that unlike the previous implementation, the ListWalker object is constructed in PopUpView (the base class) instead of the derived class. Tests added for navigation keypresses in MessageInfoView and StreamInfoView.
1 parent 3c5c915 commit 2a2ed8f

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

tests/ui/test_ui_tools.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,22 @@ def test_exit_popup_GO_BACK(self, mocker, popup_view, key):
12131213
assert self.controller.exit_popup.called
12141214

12151215

1216+
class TestStreamInfoView:
1217+
@pytest.fixture(autouse=True)
1218+
def mock_external_classes(self, mocker, monkeypatch):
1219+
self.controller = mocker.Mock()
1220+
mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
1221+
self.stream_info_view = StreamInfoView(self.controller, '', '', '')
1222+
1223+
def test_keypress_navigation(self, mocker,
1224+
navigation_key_expected_key_pair):
1225+
key, expected_key = navigation_key_expected_key_pair
1226+
size = (200, 20)
1227+
super_keypress = mocker.patch(VIEWS + '.urwid.ListBox.keypress')
1228+
self.stream_info_view.keypress(size, key)
1229+
super_keypress.assert_called_once_with(size, expected_key)
1230+
1231+
12161232
class TestMsgInfoView:
12171233
@pytest.fixture(autouse=True)
12181234
def mock_external_classes(self, mocker, monkeypatch, message_fixture):
@@ -1282,6 +1298,14 @@ def test_height_reactions(self, message_fixture, to_vary_in_each_message):
12821298
expected_height = 8
12831299
assert self.msg_info_view.height == expected_height
12841300

1301+
def test_keypress_navigation(self, mocker,
1302+
navigation_key_expected_key_pair):
1303+
key, expected_key = navigation_key_expected_key_pair
1304+
size = (200, 20)
1305+
super_keypress = mocker.patch(VIEWS + '.urwid.ListBox.keypress')
1306+
self.msg_info_view.keypress(size, key)
1307+
super_keypress.assert_called_once_with(size, expected_key)
1308+
12851309

12861310
class TestMessageBox:
12871311
@pytest.fixture(autouse=True)

zulipterminal/ui_tools/views.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -849,26 +849,18 @@ def keypress(self, size: urwid_Size, key: str) -> str:
849849
return super().keypress(size, key)
850850

851851

852-
class StreamInfoView(urwid.ListBox):
852+
class StreamInfoView(PopUpView):
853853
def __init__(self, controller: Any, color: str,
854854
name: str, desc: str) -> None:
855-
self.controller = controller
856855
# TODO: Width & Height handling could be improved
857856
self.width = max(len(desc), len("# {}".format(name)))+2
858857
self.height = 2
859-
log = [urwid.Text(desc, align='center')]
860-
super().__init__(log)
861-
862-
def keypress(self, size: Tuple[int, int], key: str) -> str:
863-
if (is_command_key('GO_BACK', key) or
864-
is_command_key('STREAM_DESC', key)):
865-
self.controller.exit_popup()
866-
return super().keypress(size, key)
858+
stream_info_content = [urwid.Text(desc, align='center')]
859+
super().__init__(controller, stream_info_content, 'STREAM_DESC')
867860

868861

869-
class MsgInfoView(urwid.ListBox):
862+
class MsgInfoView(PopUpView):
870863
def __init__(self, controller: Any, msg: Message) -> None:
871-
self.controller = controller
872864
self.msg = msg
873865

874866
if msg['reactions']:
@@ -896,18 +888,12 @@ def __init__(self, controller: Any, msg: Message) -> None:
896888
self.width = sum(max_widths)
897889
self.height = len(msg_info['Reactions'])+4 if msg['reactions'] else 5
898890

899-
self.log = urwid.SimpleListWalker(
900-
[urwid.AttrWrap(
891+
msg_info_content = [urwid.AttrWrap(
901892
urwid.Columns([
902893
urwid.Text(field),
903894
(max_widths[1], urwid.Text(data))
904895
], dividechars=2),
905896
None if index % 2 else 'bar')
906-
for index, (field, data) in enumerate(msg_info.items())])
897+
for index, (field, data) in enumerate(msg_info.items())]
907898

908-
super().__init__(self.log)
909-
910-
def keypress(self, size: urwid_Size, key: str) -> str:
911-
if is_command_key('GO_BACK', key) or is_command_key('MSG_INFO', key):
912-
self.controller.exit_popup()
913-
return super().keypress(size, key)
899+
super().__init__(controller, msg_info_content, 'MSG_INFO')

0 commit comments

Comments
 (0)