@@ -78,7 +78,7 @@ export function activateEditor(
7878 quartoContext : QuartoContext ,
7979 lspClient : LanguageClient ,
8080 engine : MarkdownEngine
81- ) : Command [ ] {
81+ ) : Command [ ] {
8282 // register the provider
8383 context . subscriptions . push ( VisualEditorProvider . register ( context , host , quartoContext , lspClient , engine ) ) ;
8484
@@ -114,30 +114,10 @@ export class VisualEditorProvider implements CustomTextEditorProvider {
114114 quartoContext : QuartoContext ,
115115 lspClient : LanguageClient ,
116116 engine : MarkdownEngine
117- ) : Disposable {
117+ ) : Disposable {
118118
119119 // setup request transport
120120 const lspRequest = lspClientTransport ( lspClient ) ;
121- context . subscriptions . push ( window . onDidChangeActiveTextEditor ( async ( ) => {
122- // Check if the document language is "quarto"
123-
124- const document = window . activeTextEditor ?. document
125- if ( ! document || document . languageId != 'quarto' ) {
126- return ;
127- }
128- const config = workspace . getConfiguration ( 'quarto' ) . get < string > ( 'defaultEditor' ) ;
129-
130- const editorMode = await determineMode ( document ) ;
131- if ( editorMode && editorMode != config ) {
132- const editorOpener = editorMode === 'visual' ? VisualEditorProvider . viewType : 'textEditor' ;
133- await commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
134- await commands . executeCommand ( "vscode.openWith" ,
135- document . uri ,
136- editorOpener
137- ) ;
138- return ;
139- }
140- } ) ) ;
141121
142122 // track edits in the active editor if its untitled. this enables us to recover the
143123 // content when we switch to an untitled document, which otherwise are just dropped
@@ -160,7 +140,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider {
160140 } ) ) ;
161141
162142 // when the active editor changes see if we have a visual editor position for it
163- context . subscriptions . push ( window . onDidChangeActiveTextEditor ( debounce ( ( ) => {
143+ context . subscriptions . push ( window . onDidChangeActiveTextEditor ( debounce ( async ( ) => {
164144 // resolve active editor
165145 const editor = window . activeTextEditor ;
166146 if ( ! editor ) {
@@ -171,6 +151,20 @@ export class VisualEditorProvider implements CustomTextEditorProvider {
171151 const uri = document . uri . toString ( ) ;
172152 // check for switch (one shot)
173153 const isSwitch = this . visualEditorPendingSwitchToSource . has ( uri ) ;
154+
155+ // see if user has specified visual or source mode
156+ const config = workspace . getConfiguration ( 'quarto' ) . get < string > ( 'defaultEditor' ) ;
157+ const editorMode = await determineMode ( document ) ;
158+ if ( editorMode && editorMode != config && ! isSwitch ) {
159+ const editorOpener = editorMode === 'visual' ? VisualEditorProvider . viewType : 'textEditor' ;
160+ await commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
161+ await commands . executeCommand ( "vscode.openWith" ,
162+ document . uri ,
163+ editorOpener
164+ ) ;
165+ return ;
166+ }
167+
174168 this . visualEditorPendingSwitchToSource . delete ( uri ) ;
175169
176170 // check for pos (one shot)
0 commit comments