Skip to content

Commit 19f1396

Browse files
zee-bitneiljp
authored andcommitted
views/buttons: 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 3347988 commit 19f1396

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
@@ -1361,6 +1361,20 @@ def test_update_emoji_list(self, emoji_units, search_string, assert_list):
13611361
assert emojis_display_name == assert_list
13621362
assert self.emoji_picker_view.get_focus() == "header"
13631363

1364+
@pytest.mark.parametrize(
1365+
"event, button, keypress",
1366+
[
1367+
("mouse press", 4, "up"),
1368+
("mouse press", 5, "down"),
1369+
],
1370+
)
1371+
def test_mouse_event(self, mocker, widget_size, event, button, keypress):
1372+
emoji_picker = self.emoji_picker_view
1373+
mocker.patch.object(emoji_picker, "keypress")
1374+
size = widget_size(emoji_picker)
1375+
emoji_picker.mouse_event(size, event, button, 0, 0, mocker.Mock())
1376+
emoji_picker.keypress.assert_called_once_with(size, keypress)
1377+
13641378
@pytest.mark.parametrize("key", keys_for_command("SEARCH_EMOJIS"))
13651379
def test_keypress_search_emoji(self, key, widget_size):
13661380
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
self.toggle_selection(self.emoji_code, self.emoji_name)
365374
is_reaction_added = self._has_user_reacted_to_msg() != self.is_selected(

zulipterminal/ui_tools/views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,21 @@ def generate_emoji_buttons(
20342034
)
20352035
return sorted_emoji_buttons
20362036

2037+
def mouse_event(
2038+
self, size: urwid_Size, event: str, button: int, col: int, row: int, focus: int
2039+
) -> bool:
2040+
if event == "mouse press":
2041+
if button == 1 and self.controller.is_in_editor_mode():
2042+
super().keypress(size, "enter")
2043+
return True
2044+
if button == 4:
2045+
self.keypress(size, "up")
2046+
return True
2047+
elif button == 5:
2048+
self.keypress(size, "down")
2049+
return True
2050+
return super().mouse_event(size, event, button, col, row, focus)
2051+
20372052
def keypress(self, size: urwid_Size, key: str) -> str:
20382053
if (
20392054
is_command_key("SEARCH_EMOJIS", key)

0 commit comments

Comments
 (0)