Skip to content

Commit

Permalink
fix search results including nulls (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners authored Feb 14, 2025
1 parent c077ee2 commit 8ba60b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.3.0",
"version": "2.3.1",
"scripts": {
"webpack": "webpack",
"clean": "rm -f *.alfredworkflow; rm -rf output/*",
Expand Down
22 changes: 19 additions & 3 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,25 @@ const alfredItem = (emojiDetails, emojiSymbol) => {

const alfredItems = (chars) => {
const items = []
chars.forEach((char) => {
items.push(alfredItem(emojiInfo[char], char))
})
for (const char of chars) {
const item = alfredItem(emojiInfo[char], char)
if (item == null) {
// If the host system being used to build the workflow has emoji
// available that emojilib hasn't incorporated yet, then we will hit
// this path. For example, as of 2025-02-14 Unicode 16.0 defines an
// emoji "face with bags under eyes" (0x01fae9) that is not present
// in the emojilib data. If we add `null` to the search results list,
// Alfred will not understand what to do with that result and will not
// display any search results for the set that includes the `null` value.
// Therefore, we have to omit it.
/*
const hex = [...char].map(c => c.codePointAt(0).toString(16)).join('')
console.log(`${char} (${hex}) is missing`)
*/
continue
}
items.push(item)
}
return { items }
}

Expand Down
7 changes: 7 additions & 0 deletions test/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
const test = require('node:test')
const search = require('../src/search')

test('does not include null results', (t) => {
t.plan(1)
const found = search('')
const filtered = found.items.filter(i => i == null)
t.assert.equal(filtered.length, 0)
})

test('finds "thumbs up"', (t) => {
t.plan(1)
const found = search('thumbs up')
Expand Down

0 comments on commit 8ba60b7

Please sign in to comment.