Skip to content

Commit ca50bf6

Browse files
committed
Add -r option: include recently accepted emojis in find results
See updated `README.adoc` to learn more. On the implementation side, I just add 1000 to the score of emojis within the "Recent" category to make them win. What's nice is the remaining score still applies over that initial 1000. Signed-off-by: Philippe Proulx <[email protected]>
1 parent c9e88bd commit ca50bf6

File tree

6 files changed

+60
-11
lines changed

6 files changed

+60
-11
lines changed

README.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,13 @@ same{nbsp}⌚.
557557
|`-R`
558558
|[[opt-R]]🙈 the "`Recent`" category.
559559

560+
|`-r`
561+
|[[opt-r]]Include the recently accepted emojis in the results
562+
when 🔍 emojis.
563+
564+
In this 💼, jome 👁️ the recently accepted emojis first within the
565+
result grid.
566+
560567
|`-k`
561568
|[[opt-k]]🙈 the keyword 📜.
562569

jome/emoji-db.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ EmojiCat::EmojiCat(QString id, QString name) :
126126
}
127127

128128
EmojiDb::EmojiDb(const QString& dir, const EmojiSize emojiSize,
129-
const unsigned int maxRecentEmojis, const bool noRecentCat) :
129+
const unsigned int maxRecentEmojis, const bool noRecentCat,
130+
const bool incRecentInFindResults) :
130131
_emojiSize {emojiSize},
131132
_emojisPngPath {qFmtFormat("{}/emojis-{}.png", dir.toStdString(), this->emojiSizeInt())},
132-
_maxRecentEmojis {maxRecentEmojis}
133+
_maxRecentEmojis {maxRecentEmojis},
134+
_incRecentInFindResults {incRecentInFindResults}
133135
{
134136
this->_createEmojis(dir);
135137
this->_createCats(dir, noRecentCat);
@@ -445,12 +447,17 @@ void EmojiDb::findEmojis(QString catName, const QString& needlesStr,
445447
// handle specific codepoint search
446448
if (needles.size() == 1 && needles.first().size() >= 3 && needles.first().startsWith("u+")) {
447449
for (auto& cat : _cats) {
448-
if (cat->isRecent()) {
449-
// exclude "Recent" category
450+
if (!catName.isEmpty() && cat->isRecent()) {
451+
// invalid
450452
continue;
451453
}
452454

453-
if (!catName.isEmpty() && !cat->lcName().contains(catName)) {
455+
if (cat->isRecent()) {
456+
if (!_incRecentInFindResults) {
457+
// exclude "Recent" category
458+
continue;
459+
}
460+
} else if (!catName.isEmpty() && !cat->lcName().contains(catName)) {
454461
// we don't even want to search this category
455462
continue;
456463
}
@@ -470,18 +477,28 @@ void EmojiDb::findEmojis(QString catName, const QString& needlesStr,
470477
auto pos = 0U;
471478

472479
for (auto& cat : _cats) {
473-
if (cat->isRecent()) {
474-
// exclude "Recent" category
480+
auto initScore = 0U;
481+
482+
if (!catName.isEmpty() && cat->isRecent()) {
483+
// invalid
475484
continue;
476485
}
477486

478-
if (!catName.isEmpty() && !cat->lcName().contains(catName)) {
487+
if (cat->isRecent()) {
488+
if (_incRecentInFindResults) {
489+
// boost to get them before the other categories
490+
initScore = 1000;
491+
} else {
492+
// exclude "Recent" category
493+
continue;
494+
}
495+
} else if (!catName.isEmpty() && !cat->lcName().contains(catName)) {
479496
// we don't even want to search this category
480497
continue;
481498
}
482499

483500
for (auto emoji : cat->emojis()) {
484-
auto score = 0U;
501+
auto score = initScore;
485502

486503
for (auto& needle : needles) {
487504
auto needleScore = 0U;

jome/emoji-db.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ class EmojiDb final
303303
* `noRecentCat` is false.
304304
*/
305305
explicit EmojiDb(const QString& dir, EmojiSize emojiSize,
306-
unsigned int maxRecentEmojis, bool noRecentCat);
306+
unsigned int maxRecentEmojis, bool noRecentCat,
307+
bool incRecentInFindResults);
307308

308309
/*
309310
* Appends the emojis found with the partial category name `cat` and
@@ -463,6 +464,7 @@ class EmojiDb final
463464
mutable std::set<const Emoji *> _tmpFindResultEmojis;
464465
EmojiCat *_recentEmojisCat = nullptr;
465466
unsigned int _maxRecentEmojis;
467+
bool _incRecentInFindResults;
466468
};
467469

468470
} // namespace jome

jome/jome.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct Params final
5454
bool noRecentCat;
5555
bool noKwList;
5656
boost::optional<jome::Emoji::SkinTone> defSkinTone;
57+
bool incRecentInFindResults;
5758
};
5859

5960
namespace {
@@ -71,6 +72,7 @@ Params parseArgs(QApplication& app)
7172
const QCommandLineOption noNlOpt {"n", "Do not output newline."};
7273
const QCommandLineOption removeVs16Opt {"V", "Do not output VS-16 codepoints."};
7374
const QCommandLineOption defSkinToneOpt {"t", "Set default skin tone to <TONE> (`L`, `ML`, `M`, `MD`, or `D`).", "TONE"};
75+
const QCommandLineOption incRecentInFindResultsOpt {"r", "Include recently accepted emojis in find results."};
7476
const QCommandLineOption cmdOpt {"c", "Execute external command <CMD> with accepted emoji.", "CMD"};
7577
const QCommandLineOption copyToClipboardOpt {"b", "Copy the accepted emoji to the clipboard."};
7678
const QCommandLineOption noHideOpt {"q", "Do not quit when accepting."};
@@ -89,6 +91,7 @@ Params parseArgs(QApplication& app)
8991
parser.addOption(noNlOpt);
9092
parser.addOption(removeVs16Opt);
9193
parser.addOption(defSkinToneOpt);
94+
parser.addOption(incRecentInFindResultsOpt);
9295
parser.addOption(cmdOpt);
9396
parser.addOption(copyToClipboardOpt);
9497
parser.addOption(noHideOpt);
@@ -114,6 +117,7 @@ Params parseArgs(QApplication& app)
114117
params.noCatLabels = parser.isSet(noCatLabelsOpt);
115118
params.noRecentCat = parser.isSet(noRecentCatOpt);
116119
params.noKwList = parser.isSet(noKwListOpt);
120+
params.incRecentInFindResults = parser.isSet(incRecentInFindResultsOpt);
117121

118122
{
119123
const auto fmt = parser.value(formatOpt);
@@ -317,7 +321,10 @@ int main(int argc, char ** const argv)
317321
const auto params = parseArgs(app);
318322

319323
// create emoji database
320-
jome::EmojiDb db {JOME_DATA_DIR, params.emojiSize, params.maxRecentEmojis, params.noRecentCat};
324+
jome::EmojiDb db {
325+
JOME_DATA_DIR, params.emojiSize, params.maxRecentEmojis, params.noRecentCat,
326+
params.incRecentInFindResults
327+
};
321328

322329
// create window (not visible yet)
323330
jome::QJomeWindow win {db, params.darkBg, params.noCatList, params.noCatLabels,

man/jome.1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,15 @@ Hide the category labels in the emoji grid.
822822
Hide the \(lqRecent\(rq category.
823823
.RE
824824
.sp
825+
\fB\-r\fP
826+
.RS 4
827+
Include the recently accepted emojis in the results when
828+
finding emojis.
829+
.sp
830+
In this case, jome shows the recently accepted emojis first within the
831+
result grid.
832+
.RE
833+
.sp
825834
\fB\-k\fP
826835
.RS 4
827836
Hide the keyword list.

man/jome.1.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ You cannot specify the **-s** and **-q** options together.
513513
**-R**::
514514
Hide the "`Recent`" category.
515515

516+
**-r**::
517+
Include the recently accepted emojis in the results when
518+
finding emojis.
519+
+
520+
In this case, jome shows the recently accepted emojis first within the
521+
result grid.
522+
516523
**-k**::
517524
Hide the keyword list.
518525

0 commit comments

Comments
 (0)