fix: format initial data boundary error #771 #784

main
Hufe921 2 years ago
parent 5285170943
commit f62a315a7b

@ -810,7 +810,7 @@ export class CommandAdapt {
tdList.push({ tdList.push({
colspan: 1, colspan: 1,
rowspan: 1, rowspan: 1,
value: [{ value: ZERO, size: 16 }] value: []
}) })
} }
trList.push(tr) trList.push(tr)

@ -1080,7 +1080,8 @@ export class Draw {
pageComponentData.forEach(data => { pageComponentData.forEach(data => {
if (!data) return if (!data) return
formatElementList(data, { formatElementList(data, {
editorOptions: this.options editorOptions: this.options,
isForceCompensation: true
}) })
}) })
this.setEditorData({ this.setEditorData({

@ -892,7 +892,8 @@ export class Control {
const elementList = zipElementList(pageComponentData[pageComponentKey]!) const elementList = zipElementList(pageComponentData[pageComponentKey]!)
pageComponentData[pageComponentKey] = elementList pageComponentData[pageComponentKey] = elementList
formatElementList(elementList, { formatElementList(elementList, {
editorOptions: this.options editorOptions: this.options,
isForceCompensation: true
}) })
} }
this.draw.setEditorData(pageComponentData) this.draw.setEditorData(pageComponentData)

@ -84,7 +84,8 @@ export class Placeholder {
} }
] ]
formatElementList(this.elementList, { formatElementList(this.elementList, {
editorOptions: this.options editorOptions: this.options,
isForceCompensation: true
}) })
// 计算 // 计算
this._compute() this._compute()

@ -89,7 +89,8 @@ export default class Editor {
] ]
pageComponentData.forEach(elementList => { pageComponentData.forEach(elementList => {
formatElementList(elementList, { formatElementList(elementList, {
editorOptions editorOptions,
isForceCompensation: true
}) })
}) })
// 监听 // 监听

@ -65,7 +65,8 @@ export function unzipElementList(elementList: IElement[]): IElement[] {
} }
interface IFormatElementListOption { interface IFormatElementListOption {
isHandleFirstElement?: boolean isHandleFirstElement?: boolean // 根据上下文确定首字符处理逻辑(处理首字符补偿)
isForceCompensation?: boolean // 强制补偿字符
editorOptions: DeepRequired<IEditorOption> editorOptions: DeepRequired<IEditorOption>
} }
@ -73,17 +74,19 @@ export function formatElementList(
elementList: IElement[], elementList: IElement[],
options: IFormatElementListOption options: IFormatElementListOption
) { ) {
const { isHandleFirstElement, editorOptions } = <IFormatElementListOption>{ const {
isHandleFirstElement: true, isHandleFirstElement = true,
...options isForceCompensation = false,
} editorOptions
} = options
const startElement = elementList[0] const startElement = elementList[0]
// 非首字符零宽节点文本元素则补偿-列表元素内部会补偿此处忽略 // 非首字符零宽节点文本元素则补偿-列表元素内部会补偿此处忽略
if ( if (
isHandleFirstElement && isForceCompensation ||
startElement?.type !== ElementType.LIST && (isHandleFirstElement &&
((startElement?.type && startElement.type !== ElementType.TEXT) || startElement?.type !== ElementType.LIST &&
!START_LINE_BREAK_REG.test(startElement?.value)) ((startElement?.type && startElement.type !== ElementType.TEXT) ||
!START_LINE_BREAK_REG.test(startElement?.value)))
) { ) {
elementList.unshift({ elementList.unshift({
value: ZERO value: ZERO
@ -100,7 +103,8 @@ export function formatElementList(
const valueList = el.valueList || [] const valueList = el.valueList || []
formatElementList(valueList, { formatElementList(valueList, {
...options, ...options,
isHandleFirstElement: false isHandleFirstElement: false,
isForceCompensation: false
}) })
// 追加节点 // 追加节点
if (valueList.length) { if (valueList.length) {
@ -134,7 +138,8 @@ export function formatElementList(
const valueList = el.valueList || [] const valueList = el.valueList || []
formatElementList(valueList, { formatElementList(valueList, {
...options, ...options,
isHandleFirstElement: true isHandleFirstElement: true,
isForceCompensation: false
}) })
// 追加节点 // 追加节点
if (valueList.length) { if (valueList.length) {
@ -170,7 +175,8 @@ export function formatElementList(
td.id = tdId td.id = tdId
formatElementList(td.value, { formatElementList(td.value, {
...options, ...options,
isHandleFirstElement: true isHandleFirstElement: true,
isForceCompensation: true
}) })
for (let v = 0; v < td.value.length; v++) { for (let v = 0; v < td.value.length; v++) {
const value = td.value[v] const value = td.value[v]
@ -385,7 +391,8 @@ export function formatElementList(
} }
formatElementList(valueList, { formatElementList(valueList, {
...options, ...options,
isHandleFirstElement: false isHandleFirstElement: false,
isForceCompensation: false
}) })
for (let v = 0; v < valueList.length; v++) { for (let v = 0; v < valueList.length; v++) {
const element = valueList[v] const element = valueList[v]

Loading…
Cancel
Save