Skip to content

Use user's selected language for next code cell #540

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
Sep 16, 2024
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 @@ -2,6 +2,7 @@

## 1.115.0

- In Source Mode, `Insert Code Cell` now places your cursor directly into the code cell if you've already specified the language in a previous cell (<https://github.com/quarto-dev/quarto/pull/540>).
- Improved reliability of sequential execution of code cells in Positron (<https://github.com/quarto-dev/quarto/pull/510>).

## 1.114.0 (Release on 06 Aug 2024)
Expand Down
19 changes: 12 additions & 7 deletions apps/vscode/src/providers/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,22 @@ class InsertCodeCellCommand implements Command {
}
}

// order by language
const allLangs = ['python', 'r', 'julia', 'ojs', 'sql', 'bash', 'mermaid', 'dot'];
const languages = language
? [language, allLangs.filter(lang => lang !== language)]
: allLangs;

// if we have a known language, use it and put the cursor directly in the
// code cell, otherwise let the user select the language first
let header;

if (language) {
header = "```{" + language + "}";
} else {
const languages = ['python', 'r', 'julia', 'ojs', 'sql', 'bash', 'mermaid', 'dot'];
header = "```{${1|" + languages.join(",") + "|}}";
}

// insert snippet
await commands.executeCommand("editor.action.insertSnippet", {
snippet: [
...(insertTopPaddingLine ? [""] : []),
"```{${1|" + languages.join(",") + "|}}",
header,
"${TM_SELECTED_TEXT}$0",
"```"
].join("\n"),
Expand Down