Skip to content

Commit

Permalink
fix: avoid deleting partial table cells (#321)
Browse files Browse the repository at this point in the history
* fix: add more judgment conditions

* fix: avoid deleting partial table cells

* Create tidy-trees-jog.md
  • Loading branch information
cycleccc committed Nov 8, 2024
1 parent 93253cd commit 58022b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/tidy-trees-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wangeditor-next/editor": patch
"@wangeditor-next/core": patch
---

319 bug 表格单元格内多选内容删除事件没有执行
15 changes: 11 additions & 4 deletions packages/core/src/text-area/event-handlers/beforeInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,19 @@ function handleBeforeInput(e: Event, textarea: TextArea, editor: IDomEditor) {
}
}

// COMPAT: If the selection is expanded, even if the command seems like
// a delete forward/backward command it should delete the selection.
if (selection && Range.isExpanded(selection) && type.startsWith('delete')) {
if (selection && Range.isExpanded(selection)) {
const selectedElems = DomEditor.getSelectedElems(editor)

if (!(selectedElems.length > 0 && selectedElems[0].type === 'table')) {
const isTableSelected = selectedElems[0].type === 'table'
const isLastNotTableCell = selectedElems[selectedElems.length - 1].type !== 'table-cell'

// 如果选中的是开头表格,并且最后不是 table-cell ,则不处理,防止选区包含部分 table 时误删 table 单元格
if (isTableSelected && isLastNotTableCell) { return }

// COMPAT: If the selection is expanded, even if the command seems like
// a delete forward/backward command it should delete the selection.
if (type.startsWith('delete')) {

const direction = type.endsWith('Backward') ? 'backward' : 'forward'

Editor.deleteFragment(editor, { direction })
Expand Down

0 comments on commit 58022b2

Please sign in to comment.