[lexical-code] Bug Fix: Allow Code Highlighter to be working in headless mode (#7538)

Co-authored-by: Baptiste Jamin <baptiste@crisp.chat>
This commit is contained in:
Baptiste Jamin
2025-05-15 20:46:35 +02:00
committed by GitHub
parent a1c5bf8028
commit b8df1e0959

View File

@ -813,23 +813,32 @@ export function registerCodeHighlighting(
tokenizer = PrismTokenizer; tokenizer = PrismTokenizer;
} }
return mergeRegister( const registrations = [];
editor.registerMutationListener(
CodeNode, // Only register the mutation listener if not in headless mode
(mutations) => { if (editor._headless !== true) {
editor.update(() => { registrations.push(
for (const [key, type] of mutations) { editor.registerMutationListener(
if (type !== 'destroyed') { CodeNode,
const node = $getNodeByKey(key); (mutations) => {
if (node !== null) { editor.update(() => {
updateCodeGutter(node as CodeNode, editor); for (const [key, type] of mutations) {
if (type !== 'destroyed') {
const node = $getNodeByKey(key);
if (node !== null) {
updateCodeGutter(node as CodeNode, editor);
}
} }
} }
} });
}); },
}, {skipInitialization: false},
{skipInitialization: false}, ),
), );
}
// Add the rest of the registrations
registrations.push(
editor.registerNodeTransform(CodeNode, (node) => editor.registerNodeTransform(CodeNode, (node) =>
codeNodeTransform(node, editor, tokenizer as Tokenizer), codeNodeTransform(node, editor, tokenizer as Tokenizer),
), ),
@ -937,4 +946,6 @@ export function registerCodeHighlighting(
COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_LOW,
), ),
); );
return mergeRegister(...registrations);
} }