Skip to content

Commit

Permalink
feat: Added search ordering based on history (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFTN authored Jul 4, 2024
2 parents a05d1b6 + b4ca897 commit fc770d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
5 changes: 3 additions & 2 deletions build/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions emoji-copy@felipeftn/emojiButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -160,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;
}

Expand Down
11 changes: 9 additions & 2 deletions emoji-copy@felipeftn/handlers/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export class SQLite {
`);
}

increment_selection(unicode) {
return 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(" ")
Expand All @@ -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;
`);
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion emoji-copy@felipeftn/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": 23
}

0 comments on commit fc770d7

Please sign in to comment.