From 082c919dd9c9f3604becee8a368afb8e6f03e3f7 Mon Sep 17 00:00:00 2001 From: Mohammed Alhaddar Date: Tue, 2 Jul 2024 21:43:44 +0300 Subject: [PATCH 1/3] Added search ordering based on history. --- build/sqlite.py | 5 +++-- emoji-copy@felipeftn/emojiButton.js | 2 ++ emoji-copy@felipeftn/handlers/sql.js | 11 +++++++++-- emoji-copy@felipeftn/metadata.json | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/build/sqlite.py b/build/sqlite.py index 3ea812c..dcaaf39 100755 --- a/build/sqlite.py +++ b/build/sqlite.py @@ -11,13 +11,14 @@ unicode VARCHAR(255) PRIMARY KEY, description VARCHAR(255), skin_tone VARCHAR(255), - emoji_group VARCHAR(255) + emoji_group VARCHAR(255), + clicked_times NUMBER default 0 ) """ # SQL query to insert/replace/update emoji in table INSERT_TBL = """ -REPLACE INTO emojis VALUES (?, ?, ?, ?) +REPLACE INTO emojis VALUES (?, ?, ?, ?, 0) """ # SQL query to get all entries from table diff --git a/emoji-copy@felipeftn/emojiButton.js b/emoji-copy@felipeftn/emojiButton.js index 1c595ec..04f6a1b 100644 --- a/emoji-copy@felipeftn/emojiButton.js +++ b/emoji-copy@felipeftn/emojiButton.js @@ -102,6 +102,7 @@ export class EmojiButton { symbol == Clutter.KP_Enter ) { let emojiToCopy = this.getTaggedEmoji(); + this.emojiCopy.sqlite.increment_selection(emojiToCopy); let [_x, _y, mods] = global.get_pointer(); let majPressed = (mods & Clutter.ModifierType.SHIFT_MASK) != 0; let ctrlPressed = (mods & Clutter.ModifierType.CONTROL_MASK) != 0; @@ -129,6 +130,7 @@ export class EmojiButton { if (emojiToCopy == null) { return Clutter.EVENT_PROPAGATE; } + this.emojiCopy.sqlite.increment_selection(emojiToCopy); if (mouseButton == 1) { return this.replaceClipboardAndClose(emojiToCopy); diff --git a/emoji-copy@felipeftn/handlers/sql.js b/emoji-copy@felipeftn/handlers/sql.js index 19c82b9..ecb7ce7 100644 --- a/emoji-copy@felipeftn/handlers/sql.js +++ b/emoji-copy@felipeftn/handlers/sql.js @@ -43,6 +43,12 @@ export class SQLite { `); } + increment_selection(unicode) { + this.query( + `UPDATE emojis SET clicked_times = clicked_times + 1 WHERE unicode = '${unicode}'` + ) + } + search_description(search_text, skin_tone = 0) { const sql_string = search_text .split(" ") @@ -53,12 +59,12 @@ export class SQLite { if (skin_tone != 0) { const skin_tone_str = this.get_skin_tone(skin_tone); return this.query(` - SELECT * FROM emojis WHERE (${sql_string}) AND skin_tone LIKE '%${skin_tone_str}%' ORDER BY LENGTH(description); + SELECT * FROM emojis WHERE (${sql_string}) AND skin_tone LIKE '%${skin_tone_str}%' ORDER BY clicked_times DESC; `); } return this.query(` - SELECT * FROM emojis WHERE ${sql_string} ORDER BY LENGTH(description); + SELECT * FROM emojis WHERE ${sql_string} ORDER BY clicked_times DESC; `); } @@ -87,6 +93,7 @@ export class SQLite { item.description = data[1]; item.skin_tone = data[2]; item.group = data[3]; + item.clicked_times = data[4] return item; }); return result; diff --git a/emoji-copy@felipeftn/metadata.json b/emoji-copy@felipeftn/metadata.json index c91a725..6180936 100644 --- a/emoji-copy@felipeftn/metadata.json +++ b/emoji-copy@felipeftn/metadata.json @@ -6,5 +6,5 @@ "url": "https://github.com/felipeftn/emoji-copy", "settings-schema": "org.gnome.shell.extensions.emoji-copy", "gettext-domain": "emoji-copy", - "version": 21 + "version": 22 } From 22ffb45187d48108788d23f6c8f3f1a86427b736 Mon Sep 17 00:00:00 2001 From: Mohammed Alhaddar Date: Tue, 2 Jul 2024 22:39:05 +0300 Subject: [PATCH 2/3] - Paste and stay now actually stays - Fixed `this` to refer to the class context --- emoji-copy@felipeftn/emojiButton.js | 12 ++---------- emoji-copy@felipeftn/metadata.json | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/emoji-copy@felipeftn/emojiButton.js b/emoji-copy@felipeftn/emojiButton.js index 04f6a1b..7f450d3 100644 --- a/emoji-copy@felipeftn/emojiButton.js +++ b/emoji-copy@felipeftn/emojiButton.js @@ -49,7 +49,7 @@ export class EmojiButton { can_focus: true, label: this.baseCharacter, }); - + // Copy the emoji to the clipboard with adequate tags and behavior this.super_btn.connect("button-press-event", this.onButtonPress.bind(this)); this.super_btn.connect("key-press-event", this.onKeyPress.bind(this)); @@ -162,25 +162,17 @@ export class EmojiButton { emojiToCopy, ); - if (this._settings.get_boolean("paste-on-select")) { - this.triggerPasteHack(); - } - return Clutter.EVENT_STOP; } addToClipboardAndStay(emojiToCopy) { - this.clipboard.get_text(CLIPBOARD_TYPE, function (_, text) { + this.clipboard.get_text(CLIPBOARD_TYPE, (_, text) => { this.clipboard.set_text( CLIPBOARD_TYPE, text + emojiToCopy, ); }); - if (this._settings.get_boolean("paste-on-select")) { - this.triggerPasteHack(); - } - return Clutter.EVENT_STOP; } diff --git a/emoji-copy@felipeftn/metadata.json b/emoji-copy@felipeftn/metadata.json index 6180936..c2c36e9 100644 --- a/emoji-copy@felipeftn/metadata.json +++ b/emoji-copy@felipeftn/metadata.json @@ -6,5 +6,5 @@ "url": "https://github.com/felipeftn/emoji-copy", "settings-schema": "org.gnome.shell.extensions.emoji-copy", "gettext-domain": "emoji-copy", - "version": 22 + "version": 23 } From 31f47cbf15ea5640f54f753b4209c305c1cdbefa Mon Sep 17 00:00:00 2001 From: Mohammed Alhaddar Date: Wed, 3 Jul 2024 18:10:24 +0300 Subject: [PATCH 3/3] Fix linting errors --- emoji-copy@felipeftn/handlers/sql.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/emoji-copy@felipeftn/handlers/sql.js b/emoji-copy@felipeftn/handlers/sql.js index ecb7ce7..4256ce5 100644 --- a/emoji-copy@felipeftn/handlers/sql.js +++ b/emoji-copy@felipeftn/handlers/sql.js @@ -44,9 +44,9 @@ export class SQLite { } increment_selection(unicode) { - this.query( - `UPDATE emojis SET clicked_times = clicked_times + 1 WHERE unicode = '${unicode}'` - ) + return this.query(` + UPDATE emojis SET clicked_times = clicked_times + 1 WHERE unicode = '${unicode}' + `); } search_description(search_text, skin_tone = 0) { @@ -93,7 +93,7 @@ export class SQLite { item.description = data[1]; item.skin_tone = data[2]; item.group = data[3]; - item.clicked_times = data[4] + item.clicked_times = data[4]; return item; }); return result;