Skip to content

Commit

Permalink
fix(table): fix merge row show error (#435)
Browse files Browse the repository at this point in the history
* fix(table): fix merge row show error

* chore: add changeset md
  • Loading branch information
cycleccc authored Dec 15, 2024
1 parent d298d36 commit 230e46d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/strong-laws-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@wangeditor-next/table-module': patch
'@wangeditor-next/editor': patch
---

fix table merge row show error
19 changes: 12 additions & 7 deletions packages/table-module/src/module/menu/MergeCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 230e46d

Please sign in to comment.