| 
13 | 13 |  *  | 
14 | 14 |  */  | 
15 | 15 | 
 
  | 
16 |  | -import { commands, window, workspace, TextDocument, ViewColumn } from "vscode";  | 
 | 16 | +import { Uri, commands, window, workspace, TextDocument, ViewColumn } from "vscode";  | 
17 | 17 | import * as quarto from "quarto-core";  | 
18 | 18 | import { Command } from "../../core/command";  | 
19 | 19 | import { isQuartoDoc, kQuartoLanguageId } from "../../core/doc";  | 
20 | 20 | import { VisualEditorProvider } from "./editor";  | 
21 |  | -import { Uri } from "vscode";  | 
22 | 21 | import { hasHooks } from "../../host/hooks";  | 
23 | 22 | import { toggleEditMode, toggleRenderOnSaveOverride } from "../context-keys";  | 
24 | 23 | 
 
  | 
@@ -130,18 +129,18 @@ export async function reopenEditorInVisualMode(  | 
130 | 129 |     // reopen in visual mode  | 
131 | 130 |     commands.executeCommand('positron.reopenWith', document.uri, 'quarto.visualEditor');  | 
132 | 131 |   } else {  | 
133 |  | -    // save then close  | 
134 |  | -    await commands.executeCommand("workbench.action.files.save");  | 
135 |  | -    await commands.executeCommand('workbench.action.closeActiveEditor');  | 
136 |  | -    VisualEditorProvider.recordPendingSwitchToVisual(document);  | 
137 |  | -    // open in visual mode  | 
138 |  | -    await commands.executeCommand("vscode.openWith",  | 
139 |  | -      document.uri,  | 
140 |  | -      VisualEditorProvider.viewType,  | 
141 |  | -      {  | 
142 |  | -        viewColumn  | 
143 |  | -      }  | 
144 |  | -    );  | 
 | 132 | +    workspace.onDidSaveTextDocument(async (doc: TextDocument) => {  | 
 | 133 | +      // open in visual mode  | 
 | 134 | +      VisualEditorProvider.recordPendingSwitchToVisual(doc);  | 
 | 135 | +      await commands.executeCommand('workbench.action.closeActiveEditor');  | 
 | 136 | +      await commands.executeCommand("vscode.openWith",  | 
 | 137 | +        doc.uri,  | 
 | 138 | +        VisualEditorProvider.viewType,  | 
 | 139 | +        { viewColumn }  | 
 | 140 | +      );  | 
 | 141 | +    });  | 
 | 142 | +    // save, which will trigger `onDidSaveTextDocument`  | 
 | 143 | +    await commands.executeCommand("workbench.action.files.save")  | 
145 | 144 |   }  | 
146 | 145 | }  | 
147 | 146 | 
 
  | 
 | 
0 commit comments