From 230e46d8a5050bc780eef1af2bd0abf04a5835a0 Mon Sep 17 00:00:00 2001 From: cycleccc <2991205548@qq.com> Date: Sun, 15 Dec 2024 22:33:04 +0800 Subject: [PATCH] fix(table): fix merge row show error (#435) * fix(table): fix merge row show error * chore: add changeset md --- .changeset/strong-laws-walk.md | 6 ++++++ .../table-module/src/module/menu/MergeCell.ts | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 .changeset/strong-laws-walk.md diff --git a/.changeset/strong-laws-walk.md b/.changeset/strong-laws-walk.md new file mode 100644 index 000000000..00c7ff1e8 --- /dev/null +++ b/.changeset/strong-laws-walk.md @@ -0,0 +1,6 @@ +--- +'@wangeditor-next/table-module': patch +'@wangeditor-next/editor': patch +--- + +fix table merge row show error diff --git a/packages/table-module/src/module/menu/MergeCell.ts b/packages/table-module/src/module/menu/MergeCell.ts index 9ab828c68..f67191504 100644 --- a/packages/table-module/src/module/menu/MergeCell.ts +++ b/packages/table-module/src/module/menu/MergeCell.ts @@ -18,6 +18,17 @@ class MergeCell implements IButtonMenu { readonly tag = 'button' + private needKeepCell(editor: Editor, trPath: Path): boolean { + // 检查同行是否有其他单元格 + const [, rowSibling] = Node.children(editor, trPath) + + // 检查同列是否有其他单元格 + const parentTable = Editor.parent(editor, trPath) + const hasOtherRows = parentTable[0].children.length > 1 + + return !!rowSibling || hasOtherRows + } + getValue(_editor: IDomEditor): string | boolean { // 无需获取 val return '' @@ -111,13 +122,7 @@ class MergeCell implements IButtonMenu { at: path, }) - const [, sibling] = Node.children(editor, trPath) - - if (sibling) { - /** - * 删除节点调整成隐藏节点 - * 隐藏节点不会影响 table 布局 - */ + if (this.needKeepCell(editor, trPath)) { Transforms.setNodes(editor, { hidden: true } as TableCellElement, { at: path }) continue }