Skip to content

Commit b73bfc3

Browse files
dani-lpetrepum
andauthored
[Lexical] Bug Fix: backspace bug when deleting nodes with canInsertTextAfter set to false (#6268)
Co-authored-by: Bob Ippolito <[email protected]>
1 parent 93b756b commit b73bfc3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/lexical/src/LexicalEvents.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,20 @@ function onBeforeInput(event: InputEvent, editor: LexicalEditor): void {
591591
// Chromium Android at the moment seems to ignore the preventDefault
592592
// on 'deleteContentBackward' and still deletes the content. Which leads
593593
// to multiple deletions. So we let the browser handle the deletion in this case.
594-
const selectedNodeText = selection.anchor.getNode().getTextContent();
594+
const selectedNode = selection.anchor.getNode();
595+
const selectedNodeText = selectedNode.getTextContent();
596+
// When the target node has `canInsertTextAfter` set to false, the first deletion
597+
// doesn't have an effect, so we need to handle it with Lexical.
598+
const selectedNodeCanInsertTextAfter =
599+
selectedNode.canInsertTextAfter();
595600
const hasSelectedAllTextInNode =
596601
selection.anchor.offset === 0 &&
597602
selection.focus.offset === selectedNodeText.length;
598603
const shouldLetBrowserHandleDelete =
599604
IS_ANDROID_CHROME &&
600605
isSelectionAnchorSameAsFocus &&
601-
!hasSelectedAllTextInNode;
606+
!hasSelectedAllTextInNode &&
607+
selectedNodeCanInsertTextAfter;
602608
if (!shouldLetBrowserHandleDelete) {
603609
dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true);
604610
}

0 commit comments

Comments
 (0)