@@ -4,9 +4,11 @@ import { OzanImagePluginSettings, DEFAULT_SETTINGS } from './settings';
44import * as ObsidianHelpers from 'src/util/obsidianHelper' ;
55import * as ImageHandler from 'src/util/imageHandler' ;
66import { buildExtension } from 'src/cm6' ;
7+ import { Extension } from '@codemirror/state' ;
78
89export default class OzanImagePlugin extends Plugin {
910 settings : OzanImagePluginSettings ;
11+ editorExtensions : Extension [ ] = [ ] ;
1012
1113 async onload ( ) {
1214 console . log ( 'Image in Editor Plugin is loaded' ) ;
@@ -77,10 +79,8 @@ export default class OzanImagePlugin extends Plugin {
7779 }
7880
7981 // --> New Editor (CM6)
80- if ( this . settings . cm6RenderAll ) {
81- const extension = buildExtension ( { plugin : this } ) ;
82- this . registerEditorExtension ( extension ) ;
83- }
82+ this . registerEditorExtension ( this . editorExtensions ) ;
83+ if ( this . settings . cm6RenderAll ) this . loadCM6Extension ( ) ;
8484
8585 // --> Custom Event Listeners
8686 document . on ( 'click' , `.oz-obsidian-inner-link` , this . onClickTransclusionLink ) ;
@@ -106,6 +106,17 @@ export default class OzanImagePlugin extends Plugin {
106106 await this . saveData ( this . settings ) ;
107107 }
108108
109+ loadCM6Extension = ( ) => {
110+ const extension = buildExtension ( { plugin : this } ) ;
111+ this . editorExtensions . push ( extension ) ;
112+ this . app . workspace . updateOptions ( ) ;
113+ } ;
114+
115+ unloadCM6Extension = ( ) => {
116+ this . editorExtensions . length = 0 ;
117+ this . app . workspace . updateOptions ( ) ;
118+ } ;
119+
109120 // Context Menu for Rendered Images
110121 onImageMenu = ( event : MouseEvent , target : HTMLElement ) => {
111122 const file = this . app . vault . getAbstractFileByPath ( target . dataset . path ) ;
0 commit comments