fix: @后会出现无法删除的情况
This commit is contained in:
parent
93887057e6
commit
95315707bf
|
@ -1,3 +1,4 @@
|
|||
import { CARD_ELEMENT_KEY } from '../../constants';
|
||||
import { EngineInterface, RangeInterface } from '../../types';
|
||||
|
||||
class Backspace {
|
||||
|
@ -44,12 +45,20 @@ class Backspace {
|
|||
if (
|
||||
cloneRange.startContainer.nodeType === Node.TEXT_NODE &&
|
||||
(function (range: RangeInterface) {
|
||||
const { commonAncestorContainer } = range;
|
||||
const { commonAncestorContainer, commonAncestorNode } =
|
||||
range;
|
||||
const commonAncestorParent = commonAncestorNode.parent();
|
||||
const commonAncestorAttributes =
|
||||
commonAncestorParent?.attributes();
|
||||
if (
|
||||
range.collapsed &&
|
||||
1 === range.startOffset &&
|
||||
range.startContainer === commonAncestorContainer &&
|
||||
commonAncestorContainer.nodeType === Node.TEXT_NODE
|
||||
commonAncestorContainer.nodeType === Node.TEXT_NODE &&
|
||||
(!commonAncestorAttributes ||
|
||||
!['left', 'right'].includes(
|
||||
commonAncestorAttributes[CARD_ELEMENT_KEY],
|
||||
))
|
||||
) {
|
||||
range = range.cloneRange();
|
||||
if (
|
||||
|
|
|
@ -49,7 +49,11 @@ class Backspace {
|
|||
*/
|
||||
trigger(event: KeyboardEvent) {
|
||||
const { change } = this.engine;
|
||||
const range = change.range.get();
|
||||
const range = change.range
|
||||
.get()
|
||||
.cloneRange()
|
||||
.shrinkToElementNode()
|
||||
.shrinkToTextNode();
|
||||
if (!range.collapsed) return;
|
||||
// 查找当前光标所在卡片
|
||||
const card = this.engine.card.find(range.startNode);
|
||||
|
|
Loading…
Reference in New Issue