Skip to content

Commit e3c70db

Browse files
committed
views: Add mouse_event support to EmojiPicker view.
This commit adds support for handling mouse_events from the emoji picker view, so that users can toggle reactions and scroll the view using their mouse. The mouse_event looks for left-click for toggling message reactions and up/down scroll to scroll through the list of emoji's from the picker. The commit is kept at the last since having mouse support is one of our least priorities for now, and providing basic functions bug-free should always come first. Tests added.
1 parent 7b1f864 commit e3c70db

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

tests/ui_tools/test_popups.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,20 @@ def test_update_emoji_list(self, emoji_units, search_string, assert_list):
13621362
assert emojis_display_name == assert_list
13631363
assert self.emoji_picker_view.get_focus() == "body"
13641364

1365+
@pytest.mark.parametrize(
1366+
"event, button, keypress",
1367+
[
1368+
("mouse press", 4, "up"),
1369+
("mouse press", 5, "down"),
1370+
],
1371+
)
1372+
def test_mouse_event(self, mocker, widget_size, event, button, keypress):
1373+
emoji_picker = self.emoji_picker_view
1374+
mocker.patch.object(emoji_picker, "keypress")
1375+
size = widget_size(emoji_picker)
1376+
emoji_picker.mouse_event(size, event, button, 0, 0, mocker.Mock())
1377+
emoji_picker.keypress.assert_called_once_with(size, keypress)
1378+
13651379
@pytest.mark.parametrize("key", keys_for_command("SEARCH_EMOJIS"))
13661380
def test_keypress_search_emoji(self, key, widget_size):
13671381
size = widget_size(self.emoji_picker_view)

zulipterminal/ui_tools/buttons.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ def get_update_widget_text(self, user_reacted: bool) -> str:
360360
reacted_check_mark = CHECK_MARK if user_reacted else ""
361361
return f" {reacted_check_mark} {count_text} "
362362

363+
def mouse_event(
364+
self, size: urwid_Size, event: str, button: int, col: int, row: int, focus: int
365+
) -> bool:
366+
if event == "mouse press":
367+
if button == 1:
368+
self.keypress(size, primary_key_for_command("ENTER"))
369+
return True
370+
return super().mouse_event(size, event, button, col, row, focus)
371+
363372
def update_emoji_button(self) -> None:
364373
if self._has_user_reacted_to_msg():
365374
self.reaction_count = (

zulipterminal/ui_tools/views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,21 @@ def generate_emoji_buttons(
20152015
)
20162016
return sorted_emoji_buttons
20172017

2018+
def mouse_event(
2019+
self, size: urwid_Size, event: str, button: int, col: int, row: int, focus: int
2020+
) -> bool:
2021+
if event == "mouse press":
2022+
if button == 1 and self.controller.is_in_editor_mode():
2023+
super().keypress(size, "enter")
2024+
return True
2025+
if button == 4:
2026+
self.keypress(size, "up")
2027+
return True
2028+
elif button == 5:
2029+
self.keypress(size, "down")
2030+
return True
2031+
return super().mouse_event(size, event, button, col, row, focus)
2032+
20182033
def keypress(self, size: urwid_Size, key: str) -> str:
20192034
if (
20202035
is_command_key("ENTER", key)

0 commit comments

Comments
 (0)