From cf477d572897ae64be2e011056b0977c69cb90b6 Mon Sep 17 00:00:00 2001 From: Kyle Butts Date: Fri, 7 Mar 2025 16:28:58 -0600 Subject: [PATCH 1/3] Add option to use theme provided cell background (#675) --- apps/vscode/package.json | 12 ++++++++++-- apps/vscode/src/providers/background.ts | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/vscode/package.json b/apps/vscode/package.json index 5aa0cd1f..5b5500ab 100644 --- a/apps/vscode/package.json +++ b/apps/vscode/package.json @@ -960,8 +960,16 @@ "default": "#40404066", "markdownDescription": "CSS color for background of executable code cells on dark themes.\n\n*Note that this color should include an alpha channel so that selections show up against the background.*" }, - "quarto.cells.background.delay": { - "order": 22, + "quarto.cells.background.useTheme": { + "order": 22, + "scope": "window", + "type": "string", + "format": "color", + "default": false, + "markdownDescription": "Should the background of executable code cells be based on the theme provided color.\n\nThis uses the `notebook.selectedCellBackground` color from the VSCode theme." + }, + "quarto.cells.background.delay": { + "order": 23, "scope": "window", "type": "integer", "default": 250, diff --git a/apps/vscode/src/providers/background.ts b/apps/vscode/src/providers/background.ts index 2aae39d7..a92ff06f 100644 --- a/apps/vscode/src/providers/background.ts +++ b/apps/vscode/src/providers/background.ts @@ -213,8 +213,16 @@ class HiglightingConfig { public sync() { const config = vscode.workspace.getConfiguration("quarto"); - const light = config.get("cells.background.light", "#E1E1E166"); - const dark = config.get("cells.background.dark", "#40404066"); + const useTheme = config.get("cells.background.useTheme", false); + let light, dark; + if (useTheme) { + const activeCellBackgroundThemeColor = new vscode.ThemeColor('notebook.selectedCellBackground'); + light = activeCellBackgroundThemeColor; + dark = activeCellBackgroundThemeColor; + } else { + light = config.get("cells.background.light", "#E1E1E166"); + dark = config.get("cells.background.dark", "#40404066"); + } this.enabled_ = config.get("cells.background.enabled", true); this.delayMs_ = config.get("cells.background.delay", 250); From 0e61dc247239c4375cce81c84e8845afb5a25c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 10 Mar 2025 15:54:36 +0100 Subject: [PATCH 2/3] fix: Ensure `#|` is added only at the beginning of a new line (#649) * fix: add offset to ensure `#|` is added at the beginning Fixes #426 * chore: add changelog entry --- apps/vscode/CHANGELOG.md | 1 + apps/vscode/src/providers/option.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/vscode/CHANGELOG.md b/apps/vscode/CHANGELOG.md index fda7a419..1e824179 100644 --- a/apps/vscode/CHANGELOG.md +++ b/apps/vscode/CHANGELOG.md @@ -4,6 +4,7 @@ - Use `QUARTO_VISUAL_EDITOR_CONFIRMED` > `PW_TEST` > `CI` to bypass (`true`) or force (`false`) the Visual Editor confirmation dialogue (). - Fix behavior in Positron when running a cell containing invalid/incomplete code (). +- Ensure `#|` is added only at the beginning of a new line (). - Fix `language` typos throughout the codebase () ## 1.118.0 (Release on 2024-11-26) diff --git a/apps/vscode/src/providers/option.ts b/apps/vscode/src/providers/option.ts index 32335087..eff92603 100644 --- a/apps/vscode/src/providers/option.ts +++ b/apps/vscode/src/providers/option.ts @@ -84,7 +84,7 @@ function handleOptionEnter(editor: TextEditor, comment: string) { }); } else if (currentLine.startsWith(optionComment)) { editor.edit((builder) => { - builder.insert(editor.selection.start.translate(1, 0), optionComment); + builder.insert(editor.selection.start.translate(1, -editor.selection.active.character), optionComment); }); } } From 28c7ca5d639918fb0f63f2ca708825bcf0640028 Mon Sep 17 00:00:00 2001 From: Kyle Butts Date: Mon, 10 Mar 2025 11:00:14 -0500 Subject: [PATCH 3/3] Simplify cell background options --- apps/vscode/package.json | 32 +++++++++++++------------ apps/vscode/src/providers/background.ts | 16 +++++++++---- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/apps/vscode/package.json b/apps/vscode/package.json index 5b5500ab..462a9b50 100644 --- a/apps/vscode/package.json +++ b/apps/vscode/package.json @@ -937,22 +937,32 @@ "default": true, "markdownDescription": "Show parameter help when editing function calls." }, - "quarto.cells.background.enabled": { + "quarto.cells.background": { "order": 19, "scope": "window", - "type": "boolean", - "default": true, - "markdownDescription": "Enable coloring the background of executable code cells." + "type": "string", + "default": "default", + "enum": [ + "default", + "useTheme", + "off" + ], + "markdownDescription": "Controls the background coloring of executable code cells.", + "enumDescriptions": [ + "Use the default light and dark background colors. Can specify colors in `quarto.cells.background.lightDefault` and `quarto.cells.background.darkDefault`", + "Use the `notebook.selectedCellBackground` color from the VS Code theme.", + "Disable background coloring of executable code cells." + ] }, - "quarto.cells.background.light": { + "quarto.cells.background.lightDefault": { "order": 20, "scope": "window", "type": "string", "format": "color", "default": "#E1E1E166", - "markdownDescription": "CSS color for background of executable code cells on light themes.\n\n*Note that this color should include an alpha channel so that selections show up against the background.*" + "markdownDescription": "CSS color for background of executable code cells on light themes. Only used when `quarto.cells.background: \"default\"`.\n\n*Note that this color should include an alpha channel so that selections show up against the background.*" }, - "quarto.cells.background.dark": { + "quarto.cells.background.darkDefault": { "order": 21, "scope": "window", "type": "string", @@ -960,14 +970,6 @@ "default": "#40404066", "markdownDescription": "CSS color for background of executable code cells on dark themes.\n\n*Note that this color should include an alpha channel so that selections show up against the background.*" }, - "quarto.cells.background.useTheme": { - "order": 22, - "scope": "window", - "type": "string", - "format": "color", - "default": false, - "markdownDescription": "Should the background of executable code cells be based on the theme provided color.\n\nThis uses the `notebook.selectedCellBackground` color from the VSCode theme." - }, "quarto.cells.background.delay": { "order": 23, "scope": "window", diff --git a/apps/vscode/src/providers/background.ts b/apps/vscode/src/providers/background.ts index a92ff06f..c234636b 100644 --- a/apps/vscode/src/providers/background.ts +++ b/apps/vscode/src/providers/background.ts @@ -192,6 +192,12 @@ function clearEditorHighlightDecorations(editor: vscode.TextEditor) { editor.setDecorations(highlightingConfig.backgroundDecoration(), []); } +enum CellBackground { + default = "default", + off = "off", + useTheme = "useTheme", +} + class HiglightingConfig { constructor() { } @@ -213,18 +219,18 @@ class HiglightingConfig { public sync() { const config = vscode.workspace.getConfiguration("quarto"); - const useTheme = config.get("cells.background.useTheme", false); + const backgroundOption = config.get("cells.background", CellBackground.default); let light, dark; - if (useTheme) { + if (backgroundOption === CellBackground.useTheme) { const activeCellBackgroundThemeColor = new vscode.ThemeColor('notebook.selectedCellBackground'); light = activeCellBackgroundThemeColor; dark = activeCellBackgroundThemeColor; } else { - light = config.get("cells.background.light", "#E1E1E166"); - dark = config.get("cells.background.dark", "#40404066"); + light = config.get("cells.background.lightDefault", "#E1E1E166"); + dark = config.get("cells.background.darkDefault", "#40404066"); } - this.enabled_ = config.get("cells.background.enabled", true); + this.enabled_ = backgroundOption !== CellBackground.off; this.delayMs_ = config.get("cells.background.delay", 250);