feat: support for inserting standard emoji #245
Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
This commit is contained in:
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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user