fix autosuggestion mixed with emoji (#154)

fixes #140
This commit is contained in:
Nolan Lawson 2018-04-17 18:38:36 -07:00 committed by GitHub
parent 980fec15ec
commit 00e71293d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 7 deletions

View file

@ -5,7 +5,6 @@ import {
} from '../_database/meta' } from '../_database/meta'
import { getCustomEmoji } from '../_api/emoji' import { getCustomEmoji } from '../_api/emoji'
import { store } from '../_store/store' import { store } from '../_store/store'
import { substring } from 'stringz'
export async function updateCustomEmojiForInstance (instanceName) { export async function updateCustomEmojiForInstance (instanceName) {
await cacheFirstUpdateAfter( await cacheFirstUpdateAfter(
@ -22,17 +21,17 @@ export async function updateCustomEmojiForInstance (instanceName) {
export function insertEmoji (realm, emoji) { export function insertEmoji (realm, emoji) {
let idx = store.get('composeSelectionStart') || 0 let idx = store.get('composeSelectionStart') || 0
let oldText = store.getComposeData(realm, 'text') let oldText = store.getComposeData(realm, 'text') || ''
let pre = oldText ? substring(oldText, 0, idx) : '' let pre = oldText.substring(0, idx)
let post = oldText ? substring(oldText, idx) : '' let post = oldText.substring(idx)
let newText = `${pre}:${emoji.shortcode}: ${post}` let newText = `${pre}:${emoji.shortcode}: ${post}`
store.setComposeData(realm, {text: newText}) store.setComposeData(realm, {text: newText})
} }
export function insertEmojiAtPosition (realm, emoji, startIndex, endIndex) { export function insertEmojiAtPosition (realm, emoji, startIndex, endIndex) {
let oldText = store.getComposeData(realm, 'text') let oldText = store.getComposeData(realm, 'text') || ''
let pre = oldText ? substring(oldText, 0, startIndex) : '' let pre = oldText.substring(0, startIndex)
let post = oldText ? substring(oldText, endIndex) : '' let post = oldText.substring(endIndex)
let newText = `${pre}:${emoji.shortcode}: ${post}` let newText = `${pre}:${emoji.shortcode}: ${post}`
store.setComposeData(realm, {text: newText}) store.setComposeData(realm, {text: newText})
} }

View file

@ -44,3 +44,39 @@ test('autosuggests custom emoji', async t => {
.pressKey('tab') .pressKey('tab')
.expect(composeInput.value).eql(':blobnom: and :blobpeek: and also :blobpats: ') .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 ')
})