fix:split emoji and rare character #50

pr675
黄云飞 4 years ago
parent 84209b719c
commit 7c37e84497

@ -60,10 +60,9 @@ export class CursorAgent {
if (item.kind === 'string') {
if (item.type === 'text/plain' && !isHTML) {
item.getAsString(plainText => {
const elementList = plainText.split('').map(value => ({
value
}))
this.draw.insertElementList(elementList)
this.draw.insertElementList([{
value: plainText
}])
})
}
if (item.type === 'text/html' && isHTML) {

@ -3,7 +3,7 @@ import { ElementType } from '../../../dataset/enum/Element'
import { IControl, IControlInitOption, IControlInstance, IControlOption } from '../../../interface/Control'
import { IElement, IElementPosition } from '../../../interface/Element'
import { IRange } from '../../../interface/Range'
import { deepClone } from '../../../utils'
import { deepClone, splitText } from '../../../utils'
import { pickElementAttr, zipElementList } from '../../../utils/element'
import { Listener } from '../../listener/Listener'
import { RangeManager } from '../../range/RangeManager'
@ -275,7 +275,7 @@ export class Control {
const startElement = elementList[startIndex]
const control = startElement.control!
if (!control.placeholder) return
const placeholderStrList = control.placeholder.split('')
const placeholderStrList = splitText(control.placeholder)
for (let p = 0; p < placeholderStrList.length; p++) {
const value = placeholderStrList[p]
elementList.splice(startIndex + p + 1, 0, {

@ -4,6 +4,7 @@ import { EditorComponent } from '../../../../dataset/enum/Editor'
import { KeyMap } from '../../../../dataset/enum/Keymap'
import { IControlInstance } from '../../../../interface/Control'
import { IElement } from '../../../../interface/Element'
import { splitText } from '../../../../utils'
import { Control } from '../Control'
export class SelectControl implements IControlInstance {
@ -185,7 +186,7 @@ export class SelectControl implements IControlInstance {
const elementList = this.control.getElementList()
const startElement = elementList[startIndex]
const start = startIndex + 1
const data = valueSet.value.split('')
const data = splitText(valueSet.value)
for (let i = 0; i < data.length; i++) {
elementList.splice(start + i, 0, {
...startElement,

@ -19,6 +19,7 @@ import { RangeManager } from '../range/RangeManager'
import { LETTER_REG, NUMBER_LIKE_REG } from '../../dataset/constant/Regular'
import { Control } from '../draw/control/Control'
import { CheckboxControl } from '../draw/control/checkbox/CheckboxControl'
import { splitText } from '../../utils'
export class CanvasEvent {
@ -518,7 +519,7 @@ export class CanvasEvent {
restArg = { tdId, trId, tableId }
}
const element = elementList[endIndex]
const inputData: IElement[] = text.split('').map(value => {
const inputData: IElement[] = splitText(text).map(value => {
const newElement: IElement = {
value,
...restArg

@ -1,4 +1,4 @@
import { deepClone, getUUID } from '.'
import { deepClone, getUUID, splitText } from '.'
import { ElementType, IEditorOption, IElement } from '..'
import { defaultCheckboxOption } from '../dataset/constant/Checkbox'
import { ZERO } from '../dataset/constant/Common'
@ -55,7 +55,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
// 元素展开
if (valueList[0].value.length > 1) {
const deleteValue = valueList.splice(0, 1)[0]
const deleteTextList = deleteValue.value.split('')
const deleteTextList = splitText(deleteValue.value)
for (let d = 0; d < deleteTextList.length; d++) {
valueList.splice(d, 0, { ...deleteValue, value: deleteTextList[d] })
}
@ -82,7 +82,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
thePrePostfixArgs.color = editorOptions.control.bracketColor
}
// 前缀
const prefixStrList = (prefix || defaultControlOption.prefix).split('')
const prefixStrList = splitText(prefix || defaultControlOption.prefix)
for (let p = 0; p < prefixStrList.length; p++) {
const value = prefixStrList[p]
elementList.splice(i, 0, {
@ -121,7 +121,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
})
i++
// 文本
const valueStrList = valueSet.value.split('')
const valueStrList = splitText(valueSet.value)
for (let e = 0; e < valueStrList.length; e++) {
const value = valueStrList[e]
const isLastLetter = e === valueStrList.length - 1
@ -150,7 +150,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
}
for (let v = 0; v < valueList.length; v++) {
const element = valueList[v]
const valueStrList = element.value.split('')
const valueStrList = splitText(element.value)
for (let e = 0; e < valueStrList.length; e++) {
const value = valueStrList[e]
elementList.splice(i, 0, {
@ -171,7 +171,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
if (editorOptions && editorOptions.control) {
thePlaceholderArgs.color = editorOptions.control.placeholderColor
}
const placeholderStrList = placeholder.split('')
const placeholderStrList = splitText(placeholder)
for (let p = 0; p < placeholderStrList.length; p++) {
const value = placeholderStrList[p]
elementList.splice(i, 0, {
@ -186,7 +186,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
}
}
// 后缀
const postfixStrList = (postfix || defaultControlOption.postfix).split('')
const postfixStrList = splitText(postfix || defaultControlOption.postfix)
for (let p = 0; p < postfixStrList.length; p++) {
const value = postfixStrList[p]
elementList.splice(i, 0, {
@ -202,7 +202,7 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme
i--
} else if ((!el.type || el.type === ElementType.TEXT) && el.value.length > 1) {
elementList.splice(i, 1)
const valueList = el.value.split('')
const valueList = splitText(el.value)
for (let v = 0; v < valueList.length; v++) {
elementList.splice(i + v, 0, { ...el, value: valueList[v] })
}

@ -51,4 +51,12 @@ export function getUUID(): string {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
}
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
}
export function splitText(text: string): string[] {
const data: string[] = []
for (const t of text) {
data.push(t)
}
return data
}
Loading…
Cancel
Save