|
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 |
|
@@ -123,20 +122,25 @@ export async function reopenEditorInVisualMode( |
123 | 122 | if (hasHooks()) { |
124 | 123 | // note pending switch to visual |
125 | 124 | VisualEditorProvider.recordPendingSwitchToVisual(document); |
| 125 | + // if document is untitled, force user to save first |
| 126 | + if (document.isUntitled) { |
| 127 | + await commands.executeCommand("workbench.action.files.save"); |
| 128 | + } |
| 129 | + // reopen in visual mode |
126 | 130 | commands.executeCommand('positron.reopenWith', document.uri, 'quarto.visualEditor'); |
127 | 131 | } else { |
128 | | - // save then close |
| 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` |
129 | 143 | await commands.executeCommand("workbench.action.files.save"); |
130 | | - await commands.executeCommand('workbench.action.closeActiveEditor'); |
131 | | - VisualEditorProvider.recordPendingSwitchToVisual(document); |
132 | | - // open in visual mode |
133 | | - await commands.executeCommand("vscode.openWith", |
134 | | - document.uri, |
135 | | - VisualEditorProvider.viewType, |
136 | | - { |
137 | | - viewColumn |
138 | | - } |
139 | | - ); |
140 | 144 | } |
141 | 145 | } |
142 | 146 |
|
|
0 commit comments