Skip to content

Commit

Permalink
fix(table): If followed by a table deleteforward is disabled (#446)
Browse files Browse the repository at this point in the history
* fix(table): If followed by a table deleteforward is disabled

* Create rotten-baboons-turn.md
  • Loading branch information
cycleccc authored Dec 17, 2024
1 parent ef81e81 commit ad3d49b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/rotten-baboons-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wangeditor-next/editor": patch
"@wangeditor-next/table-module": patch
---

fix(table): If followed by a table deleteforward is disabled
24 changes: 22 additions & 2 deletions packages/table-module/src/module/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,29 @@ function withTable<T extends IDomEditor>(editor: T): T {
newEditor.deleteForward = unit => {
const res = deleteHandler(newEditor)

if (res) { return } // 命中 table cell ,自己处理删除
if (res) { return }

if (deleteCellBreak(newEditor, unit, 'forward')) { return }

// 防止从 table 前面的 p 删除时,删除第一个 cell
const { selection } = newEditor

if (deleteCellBreak(newEditor, unit, 'forward')) { return } // 命中了 cell 内删除换行符,自行处理删除
if (selection) {
const after = Editor.after(newEditor, selection) // 后一个 location
const tableCell = Editor.above(newEditor, {
at: selection,
match: n => DomEditor.checkNodeType(n, 'table-cell'),
})

if (after) {
const isTableOnAfterLocation = isTableLocation(newEditor, after) // after 是否是 table
// 如果后面是 table, 当前是 paragraph,则不执行删除

if (!tableCell && isTableOnAfterLocation && DomEditor.getSelectedNodeByType(newEditor, 'paragraph')) {
return
}
}
}

// 执行默认的删除
deleteForward(unit)
Expand Down

0 comments on commit ad3d49b

Please sign in to comment.