Skip to content

Commit b15aa38

Browse files
juliasilgevezwork
andauthored
Force a user save on untitled documents, before switch to visual mode (#831)
* Force a user save on untitled documents, before switch to visual mode * Update CHANGELOG * Fix for opening unsaved file in VE in VSCode * Make linter happy --------- Co-authored-by: elliot <[email protected]>
1 parent 6ac1612 commit b15aa38

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

apps/vscode/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
## 1.125.0 (Unreleased)
44

55
- Fixed an issue where attribute values containing '='s could be truncated in some scenarios (<https://github.com/quarto-dev/quarto/pull/814>).
6-
- Fixed an issue where a loading spinner for qmd previews wasn't dismissed on preview errors (<https://github.com/quarto-dev/quarto/pull/823>)
6+
- Fixed an issue where a loading spinner for qmd previews wasn't dismissed on preview errors (<https://github.com/quarto-dev/quarto/pull/823>).
77
- Diagnostics are no longer reported for internal temporary virtual document files (<https://github.com/quarto-dev/quarto/pull/832>).
8+
- Fixed switching to visual mode for untitled documents in Positron (<https://github.com/quarto-dev/quarto/pull/831>).
89

910
## 1.124.0 (Release on 2025-08-20)
1011

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

Lines changed: 17 additions & 13 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

@@ -123,20 +122,25 @@ export async function reopenEditorInVisualMode(
123122
if (hasHooks()) {
124123
// note pending switch to visual
125124
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
126130
commands.executeCommand('positron.reopenWith', document.uri, 'quarto.visualEditor');
127131
} 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`
129143
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-
);
140144
}
141145
}
142146

0 commit comments

Comments
 (0)