From 1175340d0688428326aa80eb5dc1ed0040f5be65 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 24 Feb 2023 02:57:54 +0200 Subject: [PATCH] make neko's inline emoji search for substrings like the normal search --- files/assets/js/emoji_modal.js | 40 +--------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index 4741d0021..f8c67635f 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -120,44 +120,6 @@ const emojisSearchDictionary = { this.dict.splice(target ,0,new EmoijsDictNode(tag, emojiName)); }, - /** - * We find the name of each emojis that has a tag that starts with query. - * - * Basically I run a binary search to find a tag that starts with a query, then I look left and right - * for other tags tat start with the query. As the array is ordered this algo is sound. - * @param {String} tag - * @returns {Set} - */ - searchFor: function(query) { - query = query.toLowerCase() - if(this.dict.length === 0) - return new Set(); - - const result = new Set(); - - let low = 0; - let high = this.dict.length; - - while (low < high) { - let mid = (low + high) >>> 1; - if (this.dict[mid].tag < query) - low = mid + 1; - else - high = mid; - } - - let target = low; - for(let i = target; i >= 0 && this.dict[i].tag.startsWith(query); i--) - for(let j = 0; j < this.dict[i].emojiNames.length; j++) - result.add(this.dict[i].emojiNames[j]); - - for(let i = target + 1; i < this.dict.length && this.dict[i].tag.startsWith(query); i++) - for(let j = 0; j < this.dict[i].emojiNames.length; j++) - result.add(this.dict[i].emojiNames[j]); - - return result; - }, - /** * We also check for substrings! (sigh) * @param {String} tag @@ -496,7 +458,7 @@ function update_speed_emoji_modal(event) speed_carot_modal.style.top = modal_pos.y + box_coords.y + 14 + "px"; // Do the search (and do something with it) - populate_speed_emoji_modal(emojisSearchDictionary.searchFor(current_word.substr(1).replace(/#/g, "").replace(/!/g, "")), event.target); + populate_speed_emoji_modal(emojisSearchDictionary.completeSearch(current_word.substr(1).replace(/#/g, "").replace(/!/g, "")), event.target); } else {