From c6b28bec4d344d04aaf399205b39181fe006b80b Mon Sep 17 00:00:00 2001 From: Eric Handley Date: Thu, 27 Nov 2025 22:43:59 -0800 Subject: [PATCH] feat: add category-based browsing to emoji selector --- .../Panels/Launcher/Plugins/EmojiPlugin.qml | 38 +++++++++- Services/Keyboard/EmojiService.qml | 74 +++++++++++++++---- 2 files changed, 94 insertions(+), 18 deletions(-) diff --git a/Modules/Panels/Launcher/Plugins/EmojiPlugin.qml b/Modules/Panels/Launcher/Plugins/EmojiPlugin.qml index 370b1d58..202fce36 100644 --- a/Modules/Panels/Launcher/Plugins/EmojiPlugin.qml +++ b/Modules/Panels/Launcher/Plugins/EmojiPlugin.qml @@ -11,6 +11,23 @@ Item { property var launcher: null property bool handleSearch: false + property string selectedCategory: "recent" + property bool isBrowsingMode: false + + property var categoryIcons: ({ + "recent": "clock", + "people": "user", + "animals": "paw", + "nature": "leaf", + "food": "apple", + "activity": "run", + "travel": "plane", + "objects": "home", + "symbols": "star" + }) + + property var categories: ["recent", "people", "animals", "nature", "food", "activity", "travel", "objects", "symbols"] + // Force update results when emoji service loads Connections { target: EmojiService @@ -27,6 +44,13 @@ Item { Logger.i("EmojiPlugin", "Initialized"); } + function selectCategory(category) { + selectedCategory = category; + if (launcher) { + launcher.updateResults(); + } + } + // Check if this plugin handles the command function handleCommand(searchText) { return searchText.startsWith(">emoji"); @@ -65,9 +89,17 @@ Item { ]; } - const query = searchText.slice(6).trim(); - const emojis = EmojiService.search(query); - return emojis.map(formatEmojiEntry); + var query = searchText.slice(6).trim(); + + if (query === "") { + isBrowsingMode = true; + var emojis = EmojiService.getEmojisByCategory(selectedCategory); + return emojis.map(formatEmojiEntry); + } else { + isBrowsingMode = false; + var emojis = EmojiService.search(query); + return emojis.map(formatEmojiEntry); + } } // Format an emoji entry for the results list diff --git a/Services/Keyboard/EmojiService.qml b/Services/Keyboard/EmojiService.qml index 8ddb1a1b..5cbf0cc7 100644 --- a/Services/Keyboard/EmojiService.qml +++ b/Services/Keyboard/EmojiService.qml @@ -47,26 +47,70 @@ Singleton { return results; } - // Get popular emojis sorted by usage count function _getPopularEmojis(limit) { - // Create array of emojis with their usage counts - const emojisWithUsage = emojis.map(emoji => { - return { - emoji: emoji, - usageCount: usageCounts[emoji.emoji] || 0 - }; - }); + var emojisWithUsage = emojis.map(function(emoji) { + return { + emoji: emoji, + usageCount: usageCounts[emoji.emoji] || 0 + }; + }).filter(function(item) { + return item.usageCount > 0; + }); // Sort by usage count (descending), then by name - emojisWithUsage.sort((a, b) => { - if (b.usageCount !== a.usageCount) { - return b.usageCount - a.usageCount; - } - return (a.emoji.name || "").localeCompare(b.emoji.name || ""); - }); + emojisWithUsage.sort(function(a, b) { + if (b.usageCount !== a.usageCount) { + return b.usageCount - a.usageCount; + } + return (a.emoji.name || "").localeCompare(b.emoji.name || ""); + }); // Return the emoji objects limited by the specified count - return emojisWithUsage.slice(0, limit).map(item => item.emoji); + return emojisWithUsage.slice(0, limit).map(function(item) { + return item.emoji; + }); + } + + function getCategoriesWithCounts() { + if (!loaded) { + return []; + } + + var categoryCounts = {}; + + for (var i = 0; i < emojis.length; i++) { + var emoji = emojis[i]; + var category = emoji.category || "other"; + if (!categoryCounts[category]) { + categoryCounts[category] = 0; + } + categoryCounts[category]++; + } + + var categories = []; + for (var cat in categoryCounts) { + categories.push({ + name: cat, + count: categoryCounts[cat] + }); + } + + return categories; + } + + function getEmojisByCategory(category) { + if (!loaded) { + return []; + } + + // Special case: "recent" category shows popular/recently used + if (category === "recent") { + return _getPopularEmojis(50); + } + + return emojis.filter(function(emoji) { + return emoji.category === category; + }); } // Record emoji usage