Skip to content

Commit

Permalink
editor: (wip)
Browse files Browse the repository at this point in the history
Signed-off-by: 01zulfi <[email protected]>
  • Loading branch information
01zulfi committed Jan 7, 2025
1 parent 73d61c8 commit c116482
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/editor/src/extensions/code-block/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ function updateSelection(
isDocChanged: boolean,
defaultLanguage: () => string | null | undefined
) {
let isCodeBlockAdded = false;
// https://discuss.prosemirror.net/t/changed-part-of-document/992/6
const from = oldState.doc.content.findDiffStart(newState.doc.content);
const to = oldState.doc.content.findDiffEnd(newState.doc.content);
if (!from || !to || from === to.b) {
return;
}
newState.doc.nodesBetween(from, to.b, (node, pos) => {
if (node.type.name === name) {
isCodeBlockAdded = true;
}
});

const oldNodeName = oldState.selection.$head.parent.type.name;
const newNodeName = newState.selection.$head.parent.type.name;

Expand All @@ -314,6 +327,7 @@ function updateSelection(
isDocChanged ? toCodeLines(node.textContent, pos) : undefined
);
attributes.caretPosition = position;
console.log("code block", { isCodeBlockAdded });
attributes.language = node.attrs.language ?? defaultLanguage();

const { tr } = newState;
Expand Down

0 comments on commit c116482

Please sign in to comment.