diff --git a/packages/engine/src/block/typing/backspace.ts b/packages/engine/src/block/typing/backspace.ts index 33448d82..c4459e54 100644 --- a/packages/engine/src/block/typing/backspace.ts +++ b/packages/engine/src/block/typing/backspace.ts @@ -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 ( diff --git a/packages/engine/src/card/typing/backspace.ts b/packages/engine/src/card/typing/backspace.ts index 9e1dc536..6a85b65e 100644 --- a/packages/engine/src/card/typing/backspace.ts +++ b/packages/engine/src/card/typing/backspace.ts @@ -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);