Skip to content

Use new positron.reopenWith command to switch between visual/source editing #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Ensure `#|` is added only at the beginning of a new line (<https://github.com/quarto-dev/quarto/pull/649>).
- Fix `language` typos throughout the codebase (<https://github.com/quarto-dev/quarto/pull/650>)
- 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>).
- Use new command to switch between source and visual editors in Positron (<https://github.com/quarto-dev/quarto/pull/684>).

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

Expand Down
75 changes: 41 additions & 34 deletions apps/vscode/src/providers/editor/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Command } from "../../core/command";
import { isQuartoDoc, kQuartoLanguageId } from "../../core/doc";
import { VisualEditorProvider } from "./editor";
import { Uri } from "vscode";
import { hasHooks } from "../../host/hooks";

export function determineMode(text: string, uri: Uri): string | undefined {
let editorOpener = undefined;
Expand Down Expand Up @@ -100,47 +101,53 @@ export async function reopenEditorInVisualMode(
document: TextDocument,
viewColumn?: ViewColumn
) {

// save then close
await commands.executeCommand("workbench.action.files.save");
await commands.executeCommand('workbench.action.closeActiveEditor');
VisualEditorProvider.recordPendingSwitchToVisual(document);
// open in visual mode
await commands.executeCommand("vscode.openWith",
document.uri,
VisualEditorProvider.viewType,
{
viewColumn
}
);
if (hasHooks()) {
commands.executeCommand('positron.reopenWith', document.uri, 'quarto.visualEditor');
} else {
// save then close
await commands.executeCommand("workbench.action.files.save");
await commands.executeCommand('workbench.action.closeActiveEditor');
VisualEditorProvider.recordPendingSwitchToVisual(document);
// open in visual mode
await commands.executeCommand("vscode.openWith",
document.uri,
VisualEditorProvider.viewType,
{
viewColumn
}
);
}
}

export async function reopenEditorInSourceMode(
document: TextDocument,
untitledContent?: string,
viewColumn?: ViewColumn
) {
if (!document.isUntitled) {
await commands.executeCommand("workbench.action.files.save");
}

// note pending switch to source
VisualEditorProvider.recordPendingSwitchToSource(document);

// close editor (return immediately as if we don't then any
// rpc method that calls this wil result in an error b/c the webview
// has been torn down by the time we return)
commands.executeCommand('workbench.action.closeActiveEditor').then(async () => {
if (document.isUntitled) {
const doc = await workspace.openTextDocument({
language: kQuartoLanguageId,
content: untitledContent || '',
});
await window.showTextDocument(doc, viewColumn, false);
} else {
const doc = await workspace.openTextDocument(document.uri);
await window.showTextDocument(doc, viewColumn, false);
if (hasHooks()) {
commands.executeCommand('positron.reopenWith', document.uri, 'default');
} else {
if (!document.isUntitled) {
await commands.executeCommand("workbench.action.files.save");
}
});

// note pending switch to source
VisualEditorProvider.recordPendingSwitchToSource(document);

// close editor (return immediately as if we don't then any
// rpc method that calls this wil result in an error b/c the webview
// has been torn down by the time we return)
commands.executeCommand('workbench.action.closeActiveEditor').then(async () => {
if (document.isUntitled) {
const doc = await workspace.openTextDocument({
language: kQuartoLanguageId,
content: untitledContent || '',
});
await window.showTextDocument(doc, viewColumn, false);
} else {
const doc = await workspace.openTextDocument(document.uri);
await window.showTextDocument(doc, viewColumn, false);
}
});
}
}