From 00e71293d6c460f8f4b17751344a102f4b47c6f1 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 17 Apr 2018 18:38:36 -0700 Subject: [PATCH] fix autosuggestion mixed with emoji (#154) fixes #140 --- routes/_actions/emoji.js | 13 +++++----- tests/spec/018-compose-autosuggest.js | 36 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/routes/_actions/emoji.js b/routes/_actions/emoji.js index 8b48aeef..62488206 100644 --- a/routes/_actions/emoji.js +++ b/routes/_actions/emoji.js @@ -5,7 +5,6 @@ import { } from '../_database/meta' import { getCustomEmoji } from '../_api/emoji' import { store } from '../_store/store' -import { substring } from 'stringz' export async function updateCustomEmojiForInstance (instanceName) { await cacheFirstUpdateAfter( @@ -22,17 +21,17 @@ export async function updateCustomEmojiForInstance (instanceName) { export function insertEmoji (realm, emoji) { let idx = store.get('composeSelectionStart') || 0 - let oldText = store.getComposeData(realm, 'text') - let pre = oldText ? substring(oldText, 0, idx) : '' - let post = oldText ? substring(oldText, idx) : '' + let oldText = store.getComposeData(realm, 'text') || '' + let pre = oldText.substring(0, idx) + let post = oldText.substring(idx) let newText = `${pre}:${emoji.shortcode}: ${post}` store.setComposeData(realm, {text: newText}) } export function insertEmojiAtPosition (realm, emoji, startIndex, endIndex) { - let oldText = store.getComposeData(realm, 'text') - let pre = oldText ? substring(oldText, 0, startIndex) : '' - let post = oldText ? substring(oldText, endIndex) : '' + let oldText = store.getComposeData(realm, 'text') || '' + let pre = oldText.substring(0, startIndex) + let post = oldText.substring(endIndex) let newText = `${pre}:${emoji.shortcode}: ${post}` store.setComposeData(realm, {text: newText}) } diff --git a/tests/spec/018-compose-autosuggest.js b/tests/spec/018-compose-autosuggest.js index 9df5e99c..8e7a1f07 100644 --- a/tests/spec/018-compose-autosuggest.js +++ b/tests/spec/018-compose-autosuggest.js @@ -44,3 +44,39 @@ test('autosuggests custom emoji', async t => { .pressKey('tab') .expect(composeInput.value).eql(':blobnom: and :blobpeek: and also :blobpats: ') }) + +test('autosuggest custom emoji works with regular emoji - keyboard', async t => { + await t.useRole(foobarRole) + .hover(composeInput) + .typeText(composeInput, '\ud83c\udf4d :blobno') + .expect(getNthAutosuggestionResult(1).innerText).contains(':blobnom:') + .pressKey('enter') + .expect(composeInput.value).eql('\ud83c\udf4d :blobnom: ') +}) + +test('autosuggest custom emoji works with regular emoji - clicking', async t => { + await t.useRole(foobarRole) + .hover(composeInput) + .typeText(composeInput, '\ud83c\udf4d :blobno') + .expect(getNthAutosuggestionResult(1).innerText).contains(':blobnom:') + .click(getNthAutosuggestionResult(1)) + .expect(composeInput.value).eql('\ud83c\udf4d :blobnom: ') +}) + +test('autosuggest handles works with regular emoji - keyboard', async t => { + await t.useRole(foobarRole) + .hover(composeInput) + .typeText(composeInput, '\ud83c\udf4d @quu') + .expect(getNthAutosuggestionResult(1).innerText).contains('@quux') + .pressKey('enter') + .expect(composeInput.value).eql('\ud83c\udf4d @quux ') +}) + +test('autosuggest handles works with regular emoji - clicking', async t => { + await t.useRole(foobarRole) + .hover(composeInput) + .typeText(composeInput, '\ud83c\udf4d @quu') + .expect(getNthAutosuggestionResult(1).innerText).contains('@quux') + .click(getNthAutosuggestionResult(1)) + .expect(composeInput.value).eql('\ud83c\udf4d @quux ') +})