diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 1b888a4..8ab6588 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -810,7 +810,7 @@ export class CommandAdapt { tdList.push({ colspan: 1, rowspan: 1, - value: [{ value: ZERO, size: 16 }] + value: [] }) } trList.push(tr) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 2e52b5b..a0830a4 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -1080,7 +1080,8 @@ export class Draw { pageComponentData.forEach(data => { if (!data) return formatElementList(data, { - editorOptions: this.options + editorOptions: this.options, + isForceCompensation: true }) }) this.setEditorData({ diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 7c3d97f..4773787 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -892,7 +892,8 @@ export class Control { const elementList = zipElementList(pageComponentData[pageComponentKey]!) pageComponentData[pageComponentKey] = elementList formatElementList(elementList, { - editorOptions: this.options + editorOptions: this.options, + isForceCompensation: true }) } this.draw.setEditorData(pageComponentData) diff --git a/src/editor/core/draw/frame/Placeholder.ts b/src/editor/core/draw/frame/Placeholder.ts index a6e4eb1..db21327 100644 --- a/src/editor/core/draw/frame/Placeholder.ts +++ b/src/editor/core/draw/frame/Placeholder.ts @@ -84,7 +84,8 @@ export class Placeholder { } ] formatElementList(this.elementList, { - editorOptions: this.options + editorOptions: this.options, + isForceCompensation: true }) // 计算 this._compute() diff --git a/src/editor/index.ts b/src/editor/index.ts index 4cf9a1b..c7f60a3 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -89,7 +89,8 @@ export default class Editor { ] pageComponentData.forEach(elementList => { formatElementList(elementList, { - editorOptions + editorOptions, + isForceCompensation: true }) }) // 监听 diff --git a/src/editor/utils/element.ts b/src/editor/utils/element.ts index e766a7d..434f7f8 100644 --- a/src/editor/utils/element.ts +++ b/src/editor/utils/element.ts @@ -65,7 +65,8 @@ export function unzipElementList(elementList: IElement[]): IElement[] { } interface IFormatElementListOption { - isHandleFirstElement?: boolean + isHandleFirstElement?: boolean // 根据上下文确定首字符处理逻辑(处理首字符补偿) + isForceCompensation?: boolean // 强制补偿字符 editorOptions: DeepRequired } @@ -73,17 +74,19 @@ export function formatElementList( elementList: IElement[], options: IFormatElementListOption ) { - const { isHandleFirstElement, editorOptions } = { - isHandleFirstElement: true, - ...options - } + const { + isHandleFirstElement = true, + isForceCompensation = false, + editorOptions + } = options const startElement = elementList[0] // 非首字符零宽节点文本元素则补偿-列表元素内部会补偿此处忽略 if ( - isHandleFirstElement && - startElement?.type !== ElementType.LIST && - ((startElement?.type && startElement.type !== ElementType.TEXT) || - !START_LINE_BREAK_REG.test(startElement?.value)) + isForceCompensation || + (isHandleFirstElement && + startElement?.type !== ElementType.LIST && + ((startElement?.type && startElement.type !== ElementType.TEXT) || + !START_LINE_BREAK_REG.test(startElement?.value))) ) { elementList.unshift({ value: ZERO @@ -100,7 +103,8 @@ export function formatElementList( const valueList = el.valueList || [] formatElementList(valueList, { ...options, - isHandleFirstElement: false + isHandleFirstElement: false, + isForceCompensation: false }) // 追加节点 if (valueList.length) { @@ -134,7 +138,8 @@ export function formatElementList( const valueList = el.valueList || [] formatElementList(valueList, { ...options, - isHandleFirstElement: true + isHandleFirstElement: true, + isForceCompensation: false }) // 追加节点 if (valueList.length) { @@ -170,7 +175,8 @@ export function formatElementList( td.id = tdId formatElementList(td.value, { ...options, - isHandleFirstElement: true + isHandleFirstElement: true, + isForceCompensation: true }) for (let v = 0; v < td.value.length; v++) { const value = td.value[v] @@ -385,7 +391,8 @@ export function formatElementList( } formatElementList(valueList, { ...options, - isHandleFirstElement: false + isHandleFirstElement: false, + isForceCompensation: false }) for (let v = 0; v < valueList.length; v++) { const element = valueList[v]