fix: delete table row boundary error #313

pr675
Hufe921 2 years ago
parent 80f6531b96
commit 8f8bc046db

@ -871,49 +871,57 @@ export class CommandAdapt {
if (isReadonly) return if (isReadonly) return
const positionContext = this.position.getPositionContext() const positionContext = this.position.getPositionContext()
if (!positionContext.isTable) return if (!positionContext.isTable) return
const { index, trIndex } = positionContext const { index, trIndex, tdIndex } = positionContext
const originalElementList = this.draw.getOriginalElementList() const originalElementList = this.draw.getOriginalElementList()
const element = originalElementList[index!] const element = originalElementList[index!]
const curTrList = element.trList! const trList = element.trList!
const curTr = curTrList[trIndex!] const curTr = trList[trIndex!]
const curTdRowIndex = curTr.tdList[tdIndex!].rowIndex!
// 如果是最后一行,直接删除整个表格 // 如果是最后一行,直接删除整个表格
if (curTrList.length <= 1) { if (trList.length <= 1) {
this.deleteTable() this.deleteTable()
return return
} }
// 之前行缩小rowspan
for (let r = 0; r < curTdRowIndex; r++) {
const tr = trList[r]
const tdList = tr.tdList
for (let d = 0; d < tdList.length; d++) {
const td = tdList[d]
if (td.rowIndex! + td.rowspan > curTdRowIndex) {
td.rowspan--
}
}
}
// 补跨行 // 补跨行
for (let d = 0; d < curTr.tdList.length; d++) { for (let d = 0; d < curTr.tdList.length; d++) {
const td = curTr.tdList[d] const td = curTr.tdList[d]
if (td.rowspan > 1) { if (td.rowspan > 1) {
let start = trIndex! + 1 const tdId = getUUID()
while (start < trIndex! + td.rowspan) { const nextTr = trList[trIndex! + 1]
const tdId = getUUID() nextTr.tdList.splice(d, 0, {
const tr = curTrList[start] id: tdId,
tr.tdList.splice(d, 0, { rowspan: td.rowspan - 1,
id: tdId, colspan: td.colspan,
rowspan: 1, value: [
colspan: 1, {
value: [ value: ZERO,
{ size: 16,
value: ZERO, tableId: element.id,
size: 16, trId: nextTr.id,
tableId: element.id, tdId
trId: tr.id, }
tdId ]
} })
]
})
start += 1
}
} }
} }
// 删除当前行 // 删除当前行
curTrList.splice(trIndex!, 1) trList.splice(trIndex!, 1)
// 重新设置上下文 // 重新设置上下文
this.position.setPositionContext({ this.position.setPositionContext({
isTable: false isTable: false
}) })
this.range.setRange(0, 0) this.range.clearRange()
// 重新渲染 // 重新渲染
this.draw.render({ this.draw.render({
curIndex: positionContext.index curIndex: positionContext.index

Loading…
Cancel
Save