fix:replace control element

pr675
黄云飞 4 years ago
parent 2842d86b41
commit ce8fbd0b91

@ -1,6 +1,7 @@
import { WRAP, ZERO } from '../../dataset/constant/Common' import { WRAP, ZERO } from '../../dataset/constant/Common'
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element' import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
import { defaultWatermarkOption } from '../../dataset/constant/Watermark' import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
import { ControlComponent } from '../../dataset/enum/Control'
import { EditorContext, EditorMode } from '../../dataset/enum/Editor' import { EditorContext, EditorMode } from '../../dataset/enum/Editor'
import { ElementType } from '../../dataset/enum/Element' import { ElementType } from '../../dataset/enum/Element'
import { ElementStyleKey } from '../../dataset/enum/ElementStyle' import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
@ -1113,6 +1114,7 @@ export class CommandAdapt {
// 表格上下文 // 表格上下文
let curTdId = '' let curTdId = ''
// 搜索值 > 替换值:增加元素;搜索值 < 替换值:减少元素 // 搜索值 > 替换值:增加元素;搜索值 < 替换值:减少元素
let firstMatchIndex = -1
const elementList = this.draw.getOriginalElementList() const elementList = this.draw.getOriginalElementList()
for (let m = 0; m < matchList.length; m++) { for (let m = 0; m < matchList.length; m++) {
const match = matchList[m] const match = matchList[m]
@ -1147,6 +1149,15 @@ export class CommandAdapt {
} else { } else {
const curIndex = match.index + pageDiffCount const curIndex = match.index + pageDiffCount
const element = elementList[curIndex] const element = elementList[curIndex]
if (
element.type === ElementType.CONTROL
&& element.controlComponent !== ControlComponent.VALUE
) {
continue
}
if (!~firstMatchIndex) {
firstMatchIndex = m
}
if (curGroupId === match.groupId) { if (curGroupId === match.groupId) {
elementList.splice(curIndex, 1) elementList.splice(curIndex, 1)
pageDiffCount-- pageDiffCount--
@ -1167,8 +1178,9 @@ export class CommandAdapt {
} }
curGroupId = match.groupId curGroupId = match.groupId
} }
if (!~firstMatchIndex) return
// 定位-首个被匹配关键词后 // 定位-首个被匹配关键词后
const firstMatch = matchList[0] const firstMatch = matchList[firstMatchIndex]
const firstIndex = firstMatch.index + (payload.length - 1) const firstIndex = firstMatch.index + (payload.length - 1)
if (firstMatch.type === EditorContext.TABLE) { if (firstMatch.type === EditorContext.TABLE) {
const { tableIndex, trIndex, tdIndex, index } = firstMatch const { tableIndex, trIndex, tdIndex, index } = firstMatch

Loading…
Cancel
Save