diff --git a/packages/lexical-code/src/CodeHighlighter.ts b/packages/lexical-code/src/CodeHighlighter.ts index f6f5efee6..0be639fb1 100644 --- a/packages/lexical-code/src/CodeHighlighter.ts +++ b/packages/lexical-code/src/CodeHighlighter.ts @@ -310,7 +310,10 @@ function updateAndRetainSelection( updateFn: () => boolean, ): void { const selection = $getSelection(); - if (!$isRangeSelection(selection) || !selection.anchor) { + // If it's not range selection (or null selection) there's no need to change it, + // but we can still run highlighting logic + if (!$isRangeSelection(selection)) { + updateFn(); return; }