Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/stories/markdown/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Sample text here...

Syntax highlighting

\`\`\` js
\`\`\`javascript
var foo = function (bar) {
return bar++;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Plugin, PluginKey} from 'prosemirror-state';
import type {Step} from 'prosemirror-transform';
// @ts-ignore // TODO: fix cjs build
import {findChildrenByType} from 'prosemirror-utils';
import {Decoration, DecorationSet} from 'prosemirror-view';
import {Decoration, DecorationSet, type EditorView} from 'prosemirror-view';

import type {ExtensionAuto} from '../../../../core';
import {capitalize} from '../../../../lodash';
Expand Down Expand Up @@ -64,6 +64,7 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui

builder.addPlugin(() => {
let modulesLoaded = false;
let view: EditorView | null = null;

const selectItems: LangSelectItem[] = [];
const mapping: Record<string, string> = {};
Expand All @@ -90,6 +91,8 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
}
}
}

view?.dispatch(view.state.tr.setMeta(key, {modulesLoaded}));
}
});
return getDecorations(state.doc);
Expand All @@ -99,6 +102,10 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
return DecorationSet.empty;
}

if (tr.getMeta(key)?.modulesLoaded) {
return getDecorations(tr.doc);
}

if (tr.docChanged) {
const oldNodeName = oldState.selection.$head.parent.type.name;
const newNodeName = newState.selection.$head.parent.type.name;
Expand Down Expand Up @@ -143,13 +150,15 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
return decos.map(tr.mapping, tr.doc);
},
},
view: (view) =>
codeLangSelectTooltipViewCreator(
view: (v) => {
view = v;
return codeLangSelectTooltipViewCreator(
view,
selectItems,
mapping,
Boolean(opts.lineNumbers?.enabled),
),
);
},
props: {
decorations: (state) => {
return key.getState(state);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading