fix:merge cell & cancel merge cell

pr675
黄云飞 4 years ago
parent c544833f69
commit e4002c3415

@ -1,5 +1,5 @@
import { ZERO } from "../../dataset/constant/Common" import { ZERO } from "../../dataset/constant/Common"
import { EDITOR_ELEMENT_STYLE } from "../../dataset/constant/Element" import { EDITOR_ELEMENT_STYLE_ATTR } from "../../dataset/constant/Element"
import { EditorContext } from "../../dataset/enum/Editor" import { EditorContext } 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"
@ -75,7 +75,7 @@ export class CommandAdapt {
if (!selection) return if (!selection) return
const painterStyle: IElementStyle = {} const painterStyle: IElementStyle = {}
selection.forEach(s => { selection.forEach(s => {
const painterStyleKeys = EDITOR_ELEMENT_STYLE const painterStyleKeys = EDITOR_ELEMENT_STYLE_ATTR
painterStyleKeys.forEach(p => { painterStyleKeys.forEach(p => {
const key = p as keyof typeof ElementStyleKey const key = p as keyof typeof ElementStyleKey
if (painterStyle[key] === undefined) { if (painterStyle[key] === undefined) {
@ -757,11 +757,9 @@ export class CommandAdapt {
} }
} }
// 重新渲染 // 重新渲染
const { startIndex, endIndex } = this.range.getRange() const curIndex = startTd.value.length - 1
this.range.setRange(startIndex, endIndex) this.range.setRange(curIndex, curIndex)
this.draw.render({ this.draw.render()
curIndex: endIndex
})
const position = this.position.getOriginalPositionList() const position = this.position.getOriginalPositionList()
this.tableTool.render(element, position[index!]) this.tableTool.render(element, position[index!])
} }
@ -776,6 +774,7 @@ export class CommandAdapt {
const curTr = curTrList[trIndex!]! const curTr = curTrList[trIndex!]!
const curTd = curTr.tdList[tdIndex!] const curTd = curTr.tdList[tdIndex!]
if (curTd.rowspan === 1 && curTd.colspan === 1) return if (curTd.rowspan === 1 && curTd.colspan === 1) return
const colspan = curTd.colspan
// 设置跨列 // 设置跨列
if (curTd.colspan > 1) { if (curTd.colspan > 1) {
for (let c = 1; c < curTd.colspan; c++) { for (let c = 1; c < curTd.colspan; c++) {
@ -797,30 +796,30 @@ export class CommandAdapt {
} }
// 设置跨行 // 设置跨行
if (curTd.rowspan > 1) { if (curTd.rowspan > 1) {
for (let c = 1; c < curTd.rowspan; c++) { for (let r = 1; r < curTd.rowspan; r++) {
const tr = curTrList[trIndex! + c] const tr = curTrList[trIndex! + r]
const tdId = getUUID() for (let c = 0; c < colspan; c++) {
tr.tdList.splice(curTd.colIndex!, 0, { const tdId = getUUID()
id: tdId, tr.tdList.splice(curTd.colIndex!, 0, {
rowspan: 1, id: tdId,
colspan: 1, rowspan: 1,
value: [{ colspan: 1,
value: ZERO, value: [{
size: 16, value: ZERO,
tableId: element.id, size: 16,
trId: tr.id, tableId: element.id,
tdId trId: tr.id,
}] tdId
}) }]
})
}
} }
curTd.rowspan = 1 curTd.rowspan = 1
} }
// 重新渲染 // 重新渲染
const { startIndex, endIndex } = this.range.getRange() const curIndex = curTd.value.length - 1
this.range.setRange(startIndex, endIndex) this.range.setRange(curIndex, curIndex)
this.draw.render({ this.draw.render()
curIndex: endIndex
})
const position = this.position.getOriginalPositionList() const position = this.position.getOriginalPositionList()
this.tableTool.render(element, position[index!]) this.tableTool.render(element, position[index!])
} }

@ -709,15 +709,19 @@ export class Draw {
}) })
// 光标重绘 // 光标重绘
if (isSetCursor) { if (isSetCursor) {
if (curIndex === undefined) {
curIndex = positionList.length - 1
}
const positionContext = this.position.getPositionContext() const positionContext = this.position.getPositionContext()
if (positionContext.isTable) { if (positionContext.isTable) {
const { index, trIndex, tdIndex } = positionContext const { index, trIndex, tdIndex } = positionContext
const tablePosition = this.elementList[index!].trList?.[trIndex!].tdList[tdIndex!].positionList?.[curIndex!] const tablePositionList = this.elementList[index!].trList?.[trIndex!].tdList[tdIndex!].positionList
if (curIndex === undefined && tablePositionList) {
curIndex = tablePositionList.length - 1
}
const tablePosition = tablePositionList?.[curIndex!]
this.position.setCursorPosition(tablePosition || null) this.position.setCursorPosition(tablePosition || null)
} else { } else {
if (curIndex === undefined) {
curIndex = positionList.length - 1
}
this.position.setCursorPosition(positionList[curIndex!] || null) this.position.setCursorPosition(positionList[curIndex!] || null)
} }
this.cursor.drawCursor() this.cursor.drawCursor()

@ -21,6 +21,7 @@ export const EDITOR_ELEMENT_COPY_ATTR: Array<keyof IElement> = [
'highlight', 'highlight',
'underline', 'underline',
'strikeout', 'strikeout',
'rowFlex',
'url', 'url',
'hyperlinkId' 'hyperlinkId'
] ]
Loading…
Cancel
Save