Skip to content

Commit

Permalink
Merge pull request #80 from dephan0/codepoints
Browse files Browse the repository at this point in the history
Added support for copying codepoints (issue #57)
  • Loading branch information
jsumners authored May 15, 2022
2 parents c7b66bf + 748b5fd commit 821d5f0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ your clipboard.
Press <kbd>alt</kbd>+<kbd>return</kbd> (⌥↵): **Copy the code** of the selected emoji)
(e.g. `:rofl:`) to your clipboard.

Press <kbd>ctrl</kbd>+<kbd>return</kbd> (⌃↵): **Copy the codepoint** **of** the selected emoji)
(e.g. `U+1F923`) to your clipboard.

Press <kbd>shift</kbd>+<kbd>return</kbd> (⇧↵): **Copy the default symbol** of the selected emoji)
(e.g. 🤣) to your clipboard without skin tone modifier.

Expand Down
6 changes: 6 additions & 0 deletions lib/genpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ for (const emojiSymbol of emojiSymbols) {
}
keywordsMap[keyword].push(emojiSymbol)
})
emojiData[emojiSymbol].codepoint = getCodePoint(emojiSymbol)
emmojiInfo[emojiSymbol] = {
...emojiData[emojiSymbol],
keywords: emojiKeywords[emojiSymbol]
Expand All @@ -42,3 +43,8 @@ fs.writeFile(
}
}
)

function getCodePoint (char) {
const hex = char.codePointAt(0).toString(16).toUpperCase()
return hex.padStart(4, '0')
}
2 changes: 2 additions & 0 deletions src/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ alt + return (⌥↵) : Copy the code of the selected emoji (e.g. ":rofl:") to y

cmd + return (⌘↵) : Paste the symbol of the selected emoji (e.g. 🤣) directly to your frontmost application.

ctrl + return (⌃↵): Copy the codepoint of the selected emoji (e.g. "U+1F923") to your clipboard.

## Automatic Updates

This workflow will automatically check for updates at most once per day. If a new release is found, it automatically downloads and installs the latest version of the workflow. All downloads come directly from official GitHub releases.
Expand Down
6 changes: 6 additions & 0 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ const alfredItem = (emojiDetails, emojiSymbol) => {
subtitle: `${verb} "${emojiSymbol}" (${name}) ${preposition}`,
arg: emojiSymbol,
icon: { path: `./icons/${emojiDetails.slug}.png` }
},
// copy the codepoint for the emoji
ctrl: {
subtitle: `${verb} "U+${emojiDetails.codepoint}" (${emojiSymbol}) ${preposition}`,
arg: `U+${emojiDetails.codepoint}`,
icon: { path: `./icons/${emojiDetails.slug}.png` }
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,15 @@ test('handles emoji the system does not recognize', (t) => {
const item = search.internals.alfredItem(undefined, '🤷🏼')
t.equal(item, undefined)
})

test('enables ctrl-modifier', (t) => {
t.plan(1)
const found = search('hear_no_evil')
t.ok(found.items[0].mods.ctrl.arg === 'U+1F649')
})

test('pads codepoint with zeroes if needed', (t) => {
t.plan(1)
const found = search('5')
t.ok(found.items[0].mods.ctrl.arg === 'U+0035')
})

0 comments on commit 821d5f0

Please sign in to comment.