fix emoji insertion

This commit is contained in:
Nolan Lawson 2018-02-28 21:03:21 -08:00
parent cd9365cddb
commit 5424242b0f
2 changed files with 13 additions and 3 deletions

View File

@ -19,9 +19,9 @@ export async function updateCustomEmojiForInstance (instanceName) {
export function insertEmoji (emoji) {
let idx = store.get('composeSelectionStart') || 0
let oldText = store.get('rawComposeText')
let pre = substring(oldText, 0, idx)
let post = substring(oldText, idx)
let oldText = store.get('rawComposeText') || ''
let pre = oldText ? substring(oldText, 0, idx) : ''
let post = oldText ? substring(oldText, idx) : ''
let newText = `${pre}:${emoji.shortcode}: ${post}`
store.set({
rawComposeText: newText

View File

@ -81,3 +81,13 @@ test('inserts custom emoji correctly', async t => {
.click($('button img[title=":blobpeek:"]'))
.expect(composeInput.value).eql(':blobnom: hello :blobpats: world foobar :blobpeek: ')
})
test('inserts emoji without typing anything', async t => {
await t.useRole(foobarRole)
.click(emojiButton)
.click($('button img[title=":blobpats:"]'))
.expect(composeInput.value).eql(':blobpats: ')
.click(emojiButton)
.click($('button img[title=":blobpeek:"]'))
.expect(composeInput.value).eql(':blobpeek: :blobpats: ')
})