parent
980fec15ec
commit
00e71293d6
|
@ -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})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 ')
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue