@@ -37,8 +37,6 @@ import { configuredQuartoPath } from "./core/quarto";
3737import { activateDenoConfig } from "./providers/deno-config" ;
3838import { determineMode , setEditorOpener } from "./providers/editor/toggle" ;
3939
40- let suppressOpenHandler = false ;
41-
4240export async function activate ( context : vscode . ExtensionContext ) {
4341
4442 // create extension host
@@ -138,19 +136,17 @@ export async function activate(context: vscode.ExtensionContext) {
138136 }
139137 } ) ;
140138
141- const documentOpenHandler = vscode . workspace . onDidOpenTextDocument ( async ( document : vscode . TextDocument ) => {
139+ const documentOpenHandler = vscode . window . onDidChangeActiveTextEditor ( async ( ) => {
142140 // Check if the document language is "quarto"
143- const config = vscode . workspace . getConfiguration ( 'quarto' ) . get < string > ( 'defaultEditor' ) ;
144- if ( document . languageId != 'quarto' ) {
145- return ;
146- }
147- if ( suppressOpenHandler ) {
148- suppressOpenHandler = false ; // Reset the flag
141+
142+ const document = vscode . window . activeTextEditor ?. document
143+ if ( ! document || document . languageId != 'quarto' ) {
149144 return ;
150145 }
146+ const config = vscode . workspace . getConfiguration ( 'quarto' ) . get < string > ( 'defaultEditor' ) ;
147+
151148 const editorMode = await determineMode ( document . getText ( ) ) ;
152149 if ( editorMode && editorMode != config ) {
153- suppressOpenHandler = true ;
154150 const editorOpener = editorMode === 'visual' ? VisualEditorProvider . viewType : 'textEditor' ;
155151 await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
156152 await vscode . commands . executeCommand ( "vscode.openWith" ,
0 commit comments