Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

319 bug 表格单元格内多选内容删除事件没有执行 #321

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/table-module": 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