Skip to content

Commit

Permalink
Merge branch 'change-skipInitializationn-default' of https://github.c…
Browse files Browse the repository at this point in the history
…om/Shopiley/lexical into change-skipInitializationn-default
  • Loading branch information
Shopiley committed Nov 22, 2024
2 parents 3b15093 + d49dbce commit 0307ece
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 164 deletions.
10 changes: 8 additions & 2 deletions packages/lexical/src/LexicalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,20 @@ function onBeforeInput(event: InputEvent, editor: LexicalEditor): void {
// Chromium Android at the moment seems to ignore the preventDefault
// on 'deleteContentBackward' and still deletes the content. Which leads
// to multiple deletions. So we let the browser handle the deletion in this case.
const selectedNodeText = selection.anchor.getNode().getTextContent();
const selectedNode = selection.anchor.getNode();
const selectedNodeText = selectedNode.getTextContent();
// When the target node has `canInsertTextAfter` set to false, the first deletion
// doesn't have an effect, so we need to handle it with Lexical.
const selectedNodeCanInsertTextAfter =
selectedNode.canInsertTextAfter();
const hasSelectedAllTextInNode =
selection.anchor.offset === 0 &&
selection.focus.offset === selectedNodeText.length;
const shouldLetBrowserHandleDelete =
IS_ANDROID_CHROME &&
isSelectionAnchorSameAsFocus &&
!hasSelectedAllTextInNode;
!hasSelectedAllTextInNode &&
selectedNodeCanInsertTextAfter;
if (!shouldLetBrowserHandleDelete) {
dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/lexical/src/LexicalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,9 @@ export function setMutatedNode(
mutatedNodesByType.set(nodeKey, isMove ? 'updated' : mutation);
}
}

/**
* @deprecated Use {@link LexicalEditor.registerMutationListener} with `skipInitialization: false` instead.
*/
export function $nodesOfType<T extends LexicalNode>(klass: Klass<T>): Array<T> {
const klassType = klass.getType();
const editorState = getActiveEditorState();
Expand Down
Loading

0 comments on commit 0307ece

Please sign in to comment.