Skip to content

Commit

Permalink
feat: Give user option to either type out emoji or copy
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershvueli committed Jul 6, 2021
1 parent c2b4d5d commit e8e6d3a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 39 deletions.
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
Use 'Control + E' to summon Geniemoji</br></br>
Navigation:</br>
Use Arrow Keys to go up and down</br>
Press Enter to type the Emoji
Press Enter to type the Emoji,
Press Shift + Enter to copy the Emoji
</div>
</div>
</form>
Expand Down
37 changes: 31 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ function search() {
currentEmojiLength = i
// All the matching emojis are appended into answerEmojis. the '.char' is from the emoji.js file
answerEmojis += `
<button type="button" onclick="typeEmoji('${item.char}')" class="emojiButton" tabindex="${i + 2}">
<button type="button" onclick="typeEmoji(event, '${item.char}')" class="emojiButton" tabindex="${i + 2}">
${item.char}
${item.name}
</button>
</br>
` // item.char is the emoji and item.name is the emoji name, both from the emojis.js file
})
})

// If there are no matching emojis, it returns undefined. To not display 'undefined', we do the following
if (typeof (answerEmojis) !== 'string') {
Expand All @@ -74,8 +74,33 @@ document.getElementById('commandInput').addEventListener('keydown', (e) => {
})

// This is executed when an emoji button is pressed
function typeEmoji(text) {
electron.ipcRenderer.send('typeEmoji', text);
function typeEmoji(event, text) {
if (event.shiftKey) {
// User held down Shift key while selecting this emoji, let's copy it
copy(text);
} else {
// User selected emoji with no Shift key, type out selected emoji
electron.ipcRenderer.send('typeEmoji', text)
}
}

// Function to copy text to clipboard
function copy(text) {
// To copy, a text area is created, the emojiChar is added to the text area. This is then selected and copied. After it is copied, the text area is deleted
var textarea = document.createElement("textarea")
textarea.value = text
document.body.appendChild(textarea)
textarea.select()
document.execCommand("copy")
document.body.removeChild(textarea)
document.getElementById('answer').innerHTML = `
<div id="info">
Copied emoji to clipboard!</br></br>
Press Escape to close this window</br></br>
<a href="https://virejdasani.github.io/Geniemoji/" target="_blank">Geniemoji</a> (${appVersion})</br>
Developed by <a href="https://virejdasani.github.io/virej/" target="_blank">Virej Dasani</a>
</div>
`
}

// For arrow key navigation
Expand All @@ -90,7 +115,7 @@ document.addEventListener("keydown", (event) => {
// circle through emojis
// ArrowUp and focus on input field? -> select last emoji
if (tabIndex < 1) {
tabIndex = currentEmojiLength + 2 // '+2': tabIndex starts with 1, 1 = input
tabIndex = currentEmojiLength + 2 // '+2': tabIndex starts with 1, 1 = input
}
// ArrowDown and focus on last emoji? -> select input field
if (tabIndex > currentEmojiLength + 2) {
Expand All @@ -101,4 +126,4 @@ document.addEventListener("keydown", (event) => {
// set focus on element to select
newEl.focus()
}
})
})

0 comments on commit e8e6d3a

Please sign in to comment.