From df6ab2c942fcc7a164de51adb5701b8046bd8099 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sun, 25 Jun 2023 10:08:41 +0200 Subject: [PATCH] Allow searching for pasted icon [why] There are cases that I find myself into sometimes when I have the glyph with me but not its name or codepoint. It would be nice to be able to search for the codepoint and/or name of a glyph by literally putting it into the search box of the cheat-sheet. There are several reasons to know the name of the glyph, to use it in a webpage, to look for alternatives when they get removed, etc. [how] Convert high codepoint-chars to codepoint text. Fixes: #1307 Authored-by: ad-chaos Signed-off-by: Fini Jastrow --- cheat-sheet.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cheat-sheet.js b/cheat-sheet.js index 2e1d4d97f..602d89a23 100644 --- a/cheat-sheet.js +++ b/cheat-sheet.js @@ -125,14 +125,17 @@ document.addEventListener('DOMContentLoaded', function () { } function searchGlyphs() { - let searchTerm = elementGlyphSearch.value; + // Convert high codepoint-chars to codepoint text - enabling search for pasted icon + let searchTerm = [...elementGlyphSearch.value] + .map((char) => char.codePointAt(0) > 255 ? char.codePointAt(0).toString(16) : char) + .join(""); let prefixSearchEnabled = true; let emptyResultsMessage = `No matches found`; if (searchTerm === "") { // MiniSearch doesn't allow empty searches and we want to show the bottom info - emptyResultsMessage = "Enter (part) of a word to search for or enter space / blank (' ') to show all icons" + emptyResultsMessage = "Enter (part) of a word to search for or paste the icon or enter space / blank (' ') to show all icons" } else { if (searchTerm === " ") { prefixSearchEnabled = false;