[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,7 +813,11 @@ export function registerCodeHighlighting(
tokenizer = PrismTokenizer;
}
return mergeRegister(
const registrations = [];
// Only register the mutation listener if not in headless mode
if (editor._headless !== true) {
registrations.push(
editor.registerMutationListener(
CodeNode,
(mutations) => {
@ -830,6 +834,11 @@ export function registerCodeHighlighting(
},
{skipInitialization: false},
),
);
}
// Add the rest of the registrations
registrations.push(
editor.registerNodeTransform(CodeNode, (node) =>
codeNodeTransform(node, editor, tokenizer as Tokenizer),
),
@ -937,4 +946,6 @@ export function registerCodeHighlighting(
COMMAND_PRIORITY_LOW,
),
);
return mergeRegister(...registrations);
}