mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat: add category-based browsing to emoji selector
This commit is contained in:
@@ -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);
|
||||
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
|
||||
|
||||
@@ -47,18 +47,18 @@ 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 => {
|
||||
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) => {
|
||||
emojisWithUsage.sort(function(a, b) {
|
||||
if (b.usageCount !== a.usageCount) {
|
||||
return b.usageCount - a.usageCount;
|
||||
}
|
||||
@@ -66,7 +66,51 @@ Singleton {
|
||||
});
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user