Skip to content

Commit 6b416d3

Browse files
committed
Fix for opening unsaved file in VE in VSCode
1 parent 6a93a72 commit 6b416d3

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

apps/vscode/src/providers/editor/toggle.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
*
1414
*/
1515

16-
import { commands, window, workspace, TextDocument, ViewColumn } from "vscode";
16+
import { Uri, commands, window, workspace, TextDocument, ViewColumn } from "vscode";
1717
import * as quarto from "quarto-core";
1818
import { Command } from "../../core/command";
1919
import { isQuartoDoc, kQuartoLanguageId } from "../../core/doc";
2020
import { VisualEditorProvider } from "./editor";
21-
import { Uri } from "vscode";
2221
import { hasHooks } from "../../host/hooks";
2322
import { toggleEditMode, toggleRenderOnSaveOverride } from "../context-keys";
2423

@@ -130,18 +129,18 @@ export async function reopenEditorInVisualMode(
130129
// reopen in visual mode
131130
commands.executeCommand('positron.reopenWith', document.uri, 'quarto.visualEditor');
132131
} 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")
145144
}
146145
}
147146

0 commit comments

Comments
 (0)