feat: support for inserting standard emoji #245

Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
pr675
zero 3 years ago committed by GitHub
parent 1f552a05d5
commit 913b8538b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because one or more lines are too long

@ -1,3 +1,5 @@
import { EMOJI_REG } from '../dataset/constant/Regular'
export function debounce(func: Function, delay: number) { export function debounce(func: Function, delay: number) {
let timer: number let timer: number
return function (this: any, ...args: any[]) { return function (this: any, ...args: any[]) {
@ -69,8 +71,20 @@ export function getUUID(): string {
export function splitText(text: string): string[] { export function splitText(text: string): string[] {
const data: string[] = [] const data: string[] = []
for (const t of text) { const emojiMap = new Map<number, string>()
data.push(t) for (const match of text.matchAll(EMOJI_REG)) {
emojiMap.set(match.index!, match[0])
}
let t = 0
while (t < text.length) {
const emoji = emojiMap.get(t)
if (emoji) {
data.push(emoji)
t += emoji.length
} else {
data.push(text[t])
t++
}
} }
return data return data
} }

Loading…
Cancel
Save