|
14 | 14 | */ |
15 | 15 |
|
16 | 16 | import path, { extname } from "path"; |
17 | | - |
| 17 | +import { determineMode } from "./toggle" |
18 | 18 | import debounce from "lodash.debounce"; |
19 | 19 |
|
20 | | -import { |
| 20 | +import { |
21 | 21 | window, |
22 | | - workspace, |
23 | | - ExtensionContext, |
24 | | - Disposable, |
25 | | - CustomTextEditorProvider, |
26 | | - TextDocument, |
27 | | - WebviewPanel, |
28 | | - CancellationToken, |
29 | | - Uri, |
| 22 | + workspace, |
| 23 | + ExtensionContext, |
| 24 | + Disposable, |
| 25 | + CustomTextEditorProvider, |
| 26 | + TextDocument, |
| 27 | + WebviewPanel, |
| 28 | + CancellationToken, |
| 29 | + Uri, |
30 | 30 | Webview, |
31 | 31 | Range, |
32 | 32 | env, |
@@ -118,6 +118,26 @@ export class VisualEditorProvider implements CustomTextEditorProvider { |
118 | 118 |
|
119 | 119 | // setup request transport |
120 | 120 | 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 | + })); |
121 | 141 |
|
122 | 142 | // track edits in the active editor if its untitled. this enables us to recover the |
123 | 143 | // content when we switch to an untitled document, which otherwise are just dropped |
@@ -149,7 +169,6 @@ export class VisualEditorProvider implements CustomTextEditorProvider { |
149 | 169 | const document = editor.document; |
150 | 170 | if (document && isQuartoDoc(document)) { |
151 | 171 | const uri = document.uri.toString(); |
152 | | - |
153 | 172 | // check for switch (one shot) |
154 | 173 | const isSwitch = this.visualEditorPendingSwitchToSource.has(uri); |
155 | 174 | this.visualEditorPendingSwitchToSource.delete(uri); |
|
0 commit comments