Skip to content

Commit d3003fb

Browse files
zee-bitneiljp
authored andcommitted
views/core: Add search logic and full emoji list to EmojiPickerView.
This commit completes the logic of searching for emojis from the EmojiPickerView on pressing 'p' key. The search is kept dynamic for faster reacting to messages. The emoji list now also displays the full list of emoji's present in model.active_emoji_data. A few bugs related to displaying empty emoji list and searching in general have also been fixed. Tests added and amended.
1 parent 513e6e8 commit d3003fb

File tree

3 files changed

+92
-9
lines changed

3 files changed

+92
-9
lines changed

tests/ui_tools/test_popups.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,51 @@ def mock_external_classes(self, mocker, message_fixture):
13161316
self.view,
13171317
)
13181318

1319+
@pytest.mark.parametrize(
1320+
"emoji_units",
1321+
[
1322+
(
1323+
("action", "1f3ac", []),
1324+
("alien", "1f47d", ["ufo"]),
1325+
("angel", "1f47c", []),
1326+
("anger", "1f4a2", ["bam", "pow"]),
1327+
("angry", "1f620", []),
1328+
("eight", "0038-20e3", []),
1329+
("email", "2709", ["envelope", "mail"]),
1330+
("eye", "1f441", []),
1331+
("ball", "26f9", ["sports"]),
1332+
("cat", "1f408", ["meow"]),
1333+
("heart", "2764", ["love", "love_you"]),
1334+
("lightning", "1f329", ["lightning_storm"]),
1335+
("smile", "1f642", []),
1336+
("smiley", "1f603", []),
1337+
("smirk", "1f60f", ["smug"]),
1338+
("smoking", "1f6ac", []),
1339+
)
1340+
],
1341+
)
1342+
@pytest.mark.parametrize(
1343+
["search_string", "assert_list"],
1344+
[
1345+
("e", ["eight", "email", "eye"]),
1346+
("sm", ["smile", "smiley", "smirk", "smoking"]),
1347+
("ang", ["angel", "anger", "angry"]),
1348+
("abc", []),
1349+
("q", []),
1350+
],
1351+
)
1352+
def test_update_emoji_list(self, emoji_units, search_string, assert_list):
1353+
self.emoji_picker_view.emoji_buttons = (
1354+
self.emoji_picker_view.generate_emoji_buttons(emoji_units)
1355+
)
1356+
1357+
self.emoji_picker_view.update_emoji_list("SEARCH_EMOJIS", search_string)
1358+
self.emojis_display = self.emoji_picker_view.emojis_display
1359+
emojis_display_name = [emoji.emoji_name for emoji in self.emojis_display]
1360+
1361+
assert emojis_display_name == assert_list
1362+
assert self.emoji_picker_view.get_focus() == "header"
1363+
13191364
@pytest.mark.parametrize("key", keys_for_command("SEARCH_EMOJIS"))
13201365
def test_keypress_search_emoji(self, key, widget_size):
13211366
size = widget_size(self.emoji_picker_view)

zulipterminal/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ def show_msg_info(
277277
self.show_pop_up(msg_info_view, "area:msg")
278278

279279
def show_emoji_picker(self, message: Message) -> None:
280+
all_emoji_units = [
281+
(emoji_name, emoji["code"], emoji["aliases"])
282+
for emoji_name, emoji in self.model.active_emoji_data.items()
283+
]
280284
emoji_picker_view = EmojiPickerView(
281-
self,
282-
"Add/Remove Emojis",
283-
[("+1", "1f44d", ["thumbs_up", "like"])],
284-
message,
285-
self.view,
285+
self, "Add/Remove Emojis", all_emoji_units, message, self.view
286286
)
287287
self.show_pop_up(emoji_picker_view, "area:msg")
288288

zulipterminal/ui_tools/views.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Message,
3535
TidiedUserInfo,
3636
asynch,
37+
match_emoji,
3738
match_stream,
3839
match_user,
3940
)
@@ -1922,8 +1923,8 @@ def __init__(
19221923
self.message = message
19231924
self.controller = controller
19241925
self.selected_emojis: Dict[str, str] = {}
1925-
emoji_buttons = self.generate_emoji_buttons(emoji_units)
1926-
width = max(len(button.label) for button in emoji_buttons)
1926+
self.emoji_buttons = self.generate_emoji_buttons(emoji_units)
1927+
width = max(len(button.label) for button in self.emoji_buttons)
19271928
max_cols, max_rows = controller.maximum_popup_dimensions()
19281929
popup_width = min(max_cols, width)
19291930
self.emoji_search = PanelSearchBox(
@@ -1941,9 +1942,10 @@ def __init__(
19411942
brcorner="─",
19421943
)
19431944
self.empty_search = False
1945+
self.search_lock = threading.Lock()
19441946
super().__init__(
19451947
controller,
1946-
emoji_buttons,
1948+
self.emoji_buttons,
19471949
"ADD_REACTION",
19481950
popup_width,
19491951
title,
@@ -1959,7 +1961,43 @@ def update_emoji_list(
19591961
new_text: Optional[str] = None,
19601962
emoji_list: Any = None,
19611963
) -> None:
1962-
pass
1964+
"""
1965+
Updates emoji list via PanelSearchBox.
1966+
"""
1967+
assert (emoji_list is None and search_box is not None) or (
1968+
emoji_list is not None and search_box is None and new_text is None
1969+
)
1970+
1971+
# Return if the method is called by PanelSearchBox without
1972+
# self.emoji_search being defined.
1973+
if not hasattr(self, "emoji_search"):
1974+
return
1975+
1976+
with self.search_lock:
1977+
self.emojis_display = list()
1978+
if new_text and new_text != self.emoji_search.search_text:
1979+
for button in self.emoji_buttons:
1980+
if match_emoji(button.emoji_name, new_text):
1981+
self.emojis_display.append(button)
1982+
else:
1983+
for alias in button.aliases:
1984+
if match_emoji(alias, new_text):
1985+
self.emojis_display.append(button)
1986+
break
1987+
else:
1988+
self.emojis_display = self.emoji_buttons
1989+
1990+
self.empty_search = len(self.emojis_display) == 0
1991+
1992+
body_content = self.emojis_display
1993+
if self.empty_search:
1994+
body_content = [self.emoji_search.search_error]
1995+
1996+
self.contents["body"] = (
1997+
urwid.ListBox(urwid.SimpleFocusListWalker(body_content)),
1998+
None,
1999+
)
2000+
self.controller.update_screen()
19632001

19642002
def is_selected_emoji(self, emoji_name: str) -> bool:
19652003
return emoji_name in self.selected_emojis.values()

0 commit comments

Comments
 (0)