@@ -7,7 +7,7 @@ import {Plugin, PluginKey} from 'prosemirror-state';
77import type { Step } from 'prosemirror-transform' ;
88// @ts -ignore // TODO: fix cjs build
99import { findChildrenByType } from 'prosemirror-utils' ;
10- import { Decoration , DecorationSet } from 'prosemirror-view' ;
10+ import { Decoration , DecorationSet , type EditorView } from 'prosemirror-view' ;
1111
1212import type { ExtensionAuto } from '../../../../core' ;
1313import { capitalize } from '../../../../lodash' ;
@@ -64,6 +64,7 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
6464
6565 builder . addPlugin ( ( ) => {
6666 let modulesLoaded = false ;
67+ let view : EditorView | null = null ;
6768
6869 const selectItems : LangSelectItem [ ] = [ ] ;
6970 const mapping : Record < string , string > = { } ;
@@ -90,6 +91,8 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
9091 }
9192 }
9293 }
94+
95+ view ?. dispatch ( view . state . tr . setMeta ( key , { modulesLoaded} ) ) ;
9396 }
9497 } ) ;
9598 return getDecorations ( state . doc ) ;
@@ -99,6 +102,10 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
99102 return DecorationSet . empty ;
100103 }
101104
105+ if ( tr . getMeta ( key ) ?. modulesLoaded ) {
106+ return getDecorations ( tr . doc ) ;
107+ }
108+
102109 if ( tr . docChanged ) {
103110 const oldNodeName = oldState . selection . $head . parent . type . name ;
104111 const newNodeName = newState . selection . $head . parent . type . name ;
@@ -143,13 +150,15 @@ export const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (bui
143150 return decos . map ( tr . mapping , tr . doc ) ;
144151 } ,
145152 } ,
146- view : ( view ) =>
147- codeLangSelectTooltipViewCreator (
153+ view : ( v ) => {
154+ view = v ;
155+ return codeLangSelectTooltipViewCreator (
148156 view ,
149157 selectItems ,
150158 mapping ,
151159 Boolean ( opts . lineNumbers ?. enabled ) ,
152- ) ,
160+ ) ;
161+ } ,
153162 props : {
154163 decorations : ( state ) => {
155164 return key . getState ( state ) ;
0 commit comments