Skip to content

Commit 0fc0f41

Browse files
authored
Use new positron.reopenWith command to switch between visual/source editing (#684)
* Use new `positron.reopenWith` command to switch between visual/source editing * Update CHANGELOG
1 parent 43d83b2 commit 0fc0f41

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

apps/vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Ensure `#|` is added only at the beginning of a new line (<https://github.com/quarto-dev/quarto/pull/649>).
88
- Fix `language` typos throughout the codebase (<https://github.com/quarto-dev/quarto/pull/650>)
99
- Update cell background configuration to add the ability to use the appropriate theme color. The `quarto.cells.background` settings have changed names so you may need to update your configuration (<https://github.com/quarto-dev/quarto/pull/679>).
10+
- Use new command to switch between source and visual editors in Positron (<https://github.com/quarto-dev/quarto/pull/684>).
1011

1112
## 1.118.0 (Release on 2024-11-26)
1213

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

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Command } from "../../core/command";
1919
import { isQuartoDoc, kQuartoLanguageId } from "../../core/doc";
2020
import { VisualEditorProvider } from "./editor";
2121
import { Uri } from "vscode";
22+
import { hasHooks } from "../../host/hooks";
2223

2324
export function determineMode(text: string, uri: Uri): string | undefined {
2425
let editorOpener = undefined;
@@ -100,47 +101,53 @@ export async function reopenEditorInVisualMode(
100101
document: TextDocument,
101102
viewColumn?: ViewColumn
102103
) {
103-
104-
// save then close
105-
await commands.executeCommand("workbench.action.files.save");
106-
await commands.executeCommand('workbench.action.closeActiveEditor');
107-
VisualEditorProvider.recordPendingSwitchToVisual(document);
108-
// open in visual mode
109-
await commands.executeCommand("vscode.openWith",
110-
document.uri,
111-
VisualEditorProvider.viewType,
112-
{
113-
viewColumn
114-
}
115-
);
104+
if (hasHooks()) {
105+
commands.executeCommand('positron.reopenWith', document.uri, 'quarto.visualEditor');
106+
} else {
107+
// save then close
108+
await commands.executeCommand("workbench.action.files.save");
109+
await commands.executeCommand('workbench.action.closeActiveEditor');
110+
VisualEditorProvider.recordPendingSwitchToVisual(document);
111+
// open in visual mode
112+
await commands.executeCommand("vscode.openWith",
113+
document.uri,
114+
VisualEditorProvider.viewType,
115+
{
116+
viewColumn
117+
}
118+
);
119+
}
116120
}
117121

118122
export async function reopenEditorInSourceMode(
119123
document: TextDocument,
120124
untitledContent?: string,
121125
viewColumn?: ViewColumn
122126
) {
123-
if (!document.isUntitled) {
124-
await commands.executeCommand("workbench.action.files.save");
125-
}
126-
127-
// note pending switch to source
128-
VisualEditorProvider.recordPendingSwitchToSource(document);
129-
130-
// close editor (return immediately as if we don't then any
131-
// rpc method that calls this wil result in an error b/c the webview
132-
// has been torn down by the time we return)
133-
commands.executeCommand('workbench.action.closeActiveEditor').then(async () => {
134-
if (document.isUntitled) {
135-
const doc = await workspace.openTextDocument({
136-
language: kQuartoLanguageId,
137-
content: untitledContent || '',
138-
});
139-
await window.showTextDocument(doc, viewColumn, false);
140-
} else {
141-
const doc = await workspace.openTextDocument(document.uri);
142-
await window.showTextDocument(doc, viewColumn, false);
127+
if (hasHooks()) {
128+
commands.executeCommand('positron.reopenWith', document.uri, 'default');
129+
} else {
130+
if (!document.isUntitled) {
131+
await commands.executeCommand("workbench.action.files.save");
143132
}
144-
});
145133

134+
// note pending switch to source
135+
VisualEditorProvider.recordPendingSwitchToSource(document);
136+
137+
// close editor (return immediately as if we don't then any
138+
// rpc method that calls this wil result in an error b/c the webview
139+
// has been torn down by the time we return)
140+
commands.executeCommand('workbench.action.closeActiveEditor').then(async () => {
141+
if (document.isUntitled) {
142+
const doc = await workspace.openTextDocument({
143+
language: kQuartoLanguageId,
144+
content: untitledContent || '',
145+
});
146+
await window.showTextDocument(doc, viewColumn, false);
147+
} else {
148+
const doc = await workspace.openTextDocument(document.uri);
149+
await window.showTextDocument(doc, viewColumn, false);
150+
}
151+
});
152+
}
146153
}

0 commit comments

Comments
 (0)