fix: delete table row boundary error #313
This commit is contained in:
@@ -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
|
|
||||||
while (start < trIndex! + td.rowspan) {
|
|
||||||
const tdId = getUUID()
|
const tdId = getUUID()
|
||||||
const tr = curTrList[start]
|
const nextTr = trList[trIndex! + 1]
|
||||||
tr.tdList.splice(d, 0, {
|
nextTr.tdList.splice(d, 0, {
|
||||||
id: tdId,
|
id: tdId,
|
||||||
rowspan: 1,
|
rowspan: td.rowspan - 1,
|
||||||
colspan: 1,
|
colspan: td.colspan,
|
||||||
value: [
|
value: [
|
||||||
{
|
{
|
||||||
value: ZERO,
|
value: ZERO,
|
||||||
size: 16,
|
size: 16,
|
||||||
tableId: element.id,
|
tableId: element.id,
|
||||||
trId: tr.id,
|
trId: nextTr.id,
|
||||||
tdId
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user