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.kind === 'string') {
if (item.type === 'text/plain' && !isHTML) { if (item.type === 'text/plain' && !isHTML) {
item.getAsString(plainText => { item.getAsString(plainText => {
const elementList = plainText.split('').map(value => ({ this.draw.insertElementList([{
value value: plainText
})) }])
this.draw.insertElementList(elementList)
}) })
} }
if (item.type === 'text/html' && isHTML) { 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 { IControl, IControlInitOption, IControlInstance, IControlOption } from '../../../interface/Control'
import { IElement, IElementPosition } from '../../../interface/Element' import { IElement, IElementPosition } from '../../../interface/Element'
import { IRange } from '../../../interface/Range' import { IRange } from '../../../interface/Range'
import { deepClone } from '../../../utils' import { deepClone, splitText } from '../../../utils'
import { pickElementAttr, zipElementList } from '../../../utils/element' import { pickElementAttr, zipElementList } from '../../../utils/element'
import { Listener } from '../../listener/Listener' import { Listener } from '../../listener/Listener'
import { RangeManager } from '../../range/RangeManager' import { RangeManager } from '../../range/RangeManager'
@ -275,7 +275,7 @@ export class Control {
const startElement = elementList[startIndex] const startElement = elementList[startIndex]
const control = startElement.control! const control = startElement.control!
if (!control.placeholder) return if (!control.placeholder) return
const placeholderStrList = control.placeholder.split('') const placeholderStrList = splitText(control.placeholder)
for (let p = 0; p < placeholderStrList.length; p++) { for (let p = 0; p < placeholderStrList.length; p++) {
const value = placeholderStrList[p] const value = placeholderStrList[p]
elementList.splice(startIndex + p + 1, 0, { elementList.splice(startIndex + p + 1, 0, {

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

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

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

@ -52,3 +52,11 @@ export function getUUID(): string {
} }
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4()) 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