Skip to content

Commit cd181b4

Browse files
committed
use onDidChangeActiveTextEditor
1 parent ed97a28 commit cd181b4

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

apps/vscode/src/main.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ import { configuredQuartoPath } from "./core/quarto";
3737
import { activateDenoConfig } from "./providers/deno-config";
3838
import { determineMode, setEditorOpener } from "./providers/editor/toggle";
3939

40-
let suppressOpenHandler = false;
41-
4240
export 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",

packages/quarto-core/src/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function filePathForDoc(doc: Document) {
109109
return URI.parse(doc.uri).fsPath;
110110
}
111111

112-
const kRegExYAML =
112+
export const kRegExYAML =
113113
/(^)(---[ \t]*[\r\n]+(?![ \t]*[\r\n]+)[\W\w]*?[\r\n]+(?:---|\.\.\.))([ \t]*)$/gm;
114114

115115
export function isQuartoDocWithFormat(doc: Document | string, format: string) {

0 commit comments

Comments
 (0)