Skip to content

Commit

Permalink
Merge pull request #109 from rickstaa/add_shift_unicode
Browse files Browse the repository at this point in the history
feat: add shift click unicode copy
  • Loading branch information
rickstaa authored Jun 2, 2023
2 parents 3954881 + 6ba5bdf commit e1f4ec5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,26 @@ const App = () => {
*
* @param selectedEmoji Selected emoji.
*/
const handleEmojiSelect = (selectedEmoji: Emoji) => {
// Copy emoji shortcode to clipboard.
navigator.clipboard.writeText(selectedEmoji.shortcodes);
const handleEmojiSelect = (selectedEmoji: Emoji, event: PointerEvent) => {
// Copy emoji shortcode or unicode to clipboard.
if (event.shiftKey) {
navigator.clipboard.writeText(
`${String.fromCodePoint(
...selectedEmoji.unified.split("-").map((str: string) => "0x" + str)
)}`
);
} else {
navigator.clipboard.writeText(selectedEmoji.shortcodes);
}

// Display snackbar
const snackbarMessage = `Emoji ${
event.shiftKey ? "unicode" : "shortcode"
} copied to clipboard. ${!event.shiftKey ? "Hold shift for unicode." : ""}`;
setSnackPack((prev) => [
...prev,
{
message: "Emoji shortcode copied to clipboard",
message: snackbarMessage,
key: new Date().getTime(),
},
]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/EmojiPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const EmojiPicker = ({
onEmojiSelect,
locale = "en",
}: {
onEmojiSelect: (input: Emoji) => void;
onEmojiSelect: (input: Emoji, event: PointerEvent) => void;
locale?: string;
}) => {
const { mode } = useContext(ThemeContext);
Expand Down

1 comment on commit e1f4ec5

@vercel
Copy link

@vercel vercel bot commented on e1f4ec5 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.