From e4002c3415f0ea298f4bbd46e05f27365a870ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BA=91=E9=A3=9E?= Date: Wed, 29 Dec 2021 19:20:22 +0800 Subject: [PATCH] fix:merge cell & cancel merge cell --- src/editor/core/command/CommandAdapt.ts | 53 ++++++++++++------------- src/editor/core/draw/Draw.ts | 12 ++++-- src/editor/dataset/constant/Element.ts | 1 + 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 514da5d..c6ae06e 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -1,5 +1,5 @@ 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 { ElementType } from "../../dataset/enum/Element" import { ElementStyleKey } from "../../dataset/enum/ElementStyle" @@ -75,7 +75,7 @@ export class CommandAdapt { if (!selection) return const painterStyle: IElementStyle = {} selection.forEach(s => { - const painterStyleKeys = EDITOR_ELEMENT_STYLE + const painterStyleKeys = EDITOR_ELEMENT_STYLE_ATTR painterStyleKeys.forEach(p => { const key = p as keyof typeof ElementStyleKey if (painterStyle[key] === undefined) { @@ -757,11 +757,9 @@ export class CommandAdapt { } } // 重新渲染 - const { startIndex, endIndex } = this.range.getRange() - this.range.setRange(startIndex, endIndex) - this.draw.render({ - curIndex: endIndex - }) + const curIndex = startTd.value.length - 1 + this.range.setRange(curIndex, curIndex) + this.draw.render() const position = this.position.getOriginalPositionList() this.tableTool.render(element, position[index!]) } @@ -776,6 +774,7 @@ export class CommandAdapt { const curTr = curTrList[trIndex!]! const curTd = curTr.tdList[tdIndex!] if (curTd.rowspan === 1 && curTd.colspan === 1) return + const colspan = curTd.colspan // 设置跨列 if (curTd.colspan > 1) { for (let c = 1; c < curTd.colspan; c++) { @@ -797,30 +796,30 @@ export class CommandAdapt { } // 设置跨行 if (curTd.rowspan > 1) { - for (let c = 1; c < curTd.rowspan; c++) { - const tr = curTrList[trIndex! + c] - const tdId = getUUID() - tr.tdList.splice(curTd.colIndex!, 0, { - id: tdId, - rowspan: 1, - colspan: 1, - value: [{ - value: ZERO, - size: 16, - tableId: element.id, - trId: tr.id, - tdId - }] - }) + for (let r = 1; r < curTd.rowspan; r++) { + const tr = curTrList[trIndex! + r] + for (let c = 0; c < colspan; c++) { + const tdId = getUUID() + tr.tdList.splice(curTd.colIndex!, 0, { + id: tdId, + rowspan: 1, + colspan: 1, + value: [{ + value: ZERO, + size: 16, + tableId: element.id, + trId: tr.id, + tdId + }] + }) + } } curTd.rowspan = 1 } // 重新渲染 - const { startIndex, endIndex } = this.range.getRange() - this.range.setRange(startIndex, endIndex) - this.draw.render({ - curIndex: endIndex - }) + const curIndex = curTd.value.length - 1 + this.range.setRange(curIndex, curIndex) + this.draw.render() const position = this.position.getOriginalPositionList() this.tableTool.render(element, position[index!]) } diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 83882ad..812074a 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -709,15 +709,19 @@ export class Draw { }) // 光标重绘 if (isSetCursor) { - if (curIndex === undefined) { - curIndex = positionList.length - 1 - } const positionContext = this.position.getPositionContext() if (positionContext.isTable) { 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) } else { + if (curIndex === undefined) { + curIndex = positionList.length - 1 + } this.position.setCursorPosition(positionList[curIndex!] || null) } this.cursor.drawCursor() diff --git a/src/editor/dataset/constant/Element.ts b/src/editor/dataset/constant/Element.ts index 38e8f29..8eac0f4 100644 --- a/src/editor/dataset/constant/Element.ts +++ b/src/editor/dataset/constant/Element.ts @@ -21,6 +21,7 @@ export const EDITOR_ELEMENT_COPY_ATTR: Array = [ 'highlight', 'underline', 'strikeout', + 'rowFlex', 'url', 'hyperlinkId' ] \ No newline at end of file