feat: support for inserting standard emoji #245

Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
This commit is contained in:
zero
2023-08-16 22:16:10 +08:00
committed by GitHub
co-authored by Hufe921
parent 1f552a05d5
commit 913b8538b7
2 changed files with 19 additions and 2 deletions
File diff suppressed because one or more lines are too long
+16 -2
View File
@@ -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
} }