@@ -4,20 +4,22 @@ import type {BlockInfo} from "@codemirror/view";
44
55export function codeBlockPostProcessorUpdate ( app : App , language : string ) {
66 for ( const leaf of app . workspace . getLeavesOfType ( "markdown" ) ) {
7- const view = < MarkdownView > leaf . view ;
8- if ( view . editor . cm ) {
9- const widgets = view . editor . cm . viewportLineBlocks . filter ( ( block : BlockInfo ) =>
10- block . widget && block . widget . lang === language
11- ) ;
12- const original_selection = view . editor . cm . state . selection ;
13- view . editor . cm . dispatch ( {
14- selection : EditorSelection . create ( widgets . map ( ( block : BlockInfo ) => EditorSelection . range ( block . from , block . to ) ) ) ,
15- scrollIntoView : false ,
16- } ) ;
17- view . editor . cm . dispatch ( {
18- selection : original_selection ,
19- scrollIntoView : false ,
20- } ) ;
7+ if ( leaf . view instanceof MarkdownView ) {
8+ const { view } = leaf ;
9+ if ( view . editor . cm ) {
10+ const widgets = view . editor . cm . viewportLineBlocks . filter ( ( block : BlockInfo ) =>
11+ block . widget && block . widget . lang === language
12+ ) ;
13+ const original_selection = view . editor . cm . state . selection ;
14+ view . editor . cm . dispatch ( {
15+ selection : EditorSelection . create ( widgets . map ( ( block : BlockInfo ) => EditorSelection . range ( block . from , block . to ) ) ) ,
16+ scrollIntoView : false ,
17+ } ) ;
18+ view . editor . cm . dispatch ( {
19+ selection : original_selection ,
20+ scrollIntoView : false ,
21+ } ) ;
22+ }
2123 }
2224 }
2325}
@@ -39,5 +41,7 @@ export function postProcessorUpdate(app: App) {
3941
4042export function postProcessorRerender ( app : App ) {
4143 for ( const leaf of app . workspace . getLeavesOfType ( "markdown" ) )
42- ( leaf . view as MarkdownView ) . previewMode . rerender ( true ) ;
44+ if ( leaf . view instanceof MarkdownView ) {
45+ leaf . view . previewMode . rerender ( true ) ;
46+ }
4347}
0 commit comments