Skip to content

Commit fc84895

Browse files
Add option to use theme provided cell background (#675) (#679)
* Add option to use theme provided cell background (#675) * Clarify descriptions, add deprecation for old setting * Update CHANGELOG --------- Co-authored-by: Julia Silge <[email protected]>
1 parent e268ba4 commit fc84895

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

apps/vscode/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Fix behavior in Positron when running a cell containing invalid/incomplete code (<https://github.com/quarto-dev/quarto/pull/664>).
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>)
9+
- 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/650>).
910

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

apps/vscode/package.json

+19-8
Original file line numberDiff line numberDiff line change
@@ -937,28 +937,39 @@
937937
"default": true,
938938
"markdownDescription": "Show parameter help when editing function calls."
939939
},
940-
"quarto.cells.background.enabled": {
940+
"quarto.cells.background.enable": {
941+
"type": "boolean",
942+
"description": "Enable coloring the background of executable code cells.",
943+
"deprecationMessage": "Deprecated: Please use quarto.cells.background.color instead."
944+
},
945+
"quarto.cells.background.color": {
941946
"order": 19,
942947
"scope": "window",
943-
"type": "boolean",
944-
"default": true,
945-
"markdownDescription": "Enable coloring the background of executable code cells."
948+
"type": "string",
949+
"markdownDescription": "Control the background coloring of executable code cells.",
950+
"default": "default",
951+
"enum": ["default", "useTheme", "off"],
952+
"markdownEnumDescriptions": [
953+
"Use the default light and dark background colors. Specify these colors with `quarto.cells.background.lightDefault` and `quarto.cells.background.darkDefault`.",
954+
"Use the `notebook.selectedCellBackground` color from the current VS Code theme.",
955+
"Disable background coloring of executable code cells."
956+
]
946957
},
947-
"quarto.cells.background.light": {
958+
"quarto.cells.background.lightDefault": {
948959
"order": 20,
949960
"scope": "window",
950961
"type": "string",
951962
"format": "color",
952963
"default": "#E1E1E166",
953-
"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.*"
964+
"markdownDescription": "CSS color for background of executable code cells on light themes.\n\n*Note that this color should include an alpha channel, like #RRGGBBAA, so that selections show up against the background.*"
954965
},
955-
"quarto.cells.background.dark": {
966+
"quarto.cells.background.darkDefault": {
956967
"order": 21,
957968
"scope": "window",
958969
"type": "string",
959970
"format": "color",
960971
"default": "#40404066",
961-
"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.*"
972+
"markdownDescription": "CSS color for background of executable code cells on dark themes.\n\n*Note that this color should include an alpha channel, like #RRGGBBAA, so that selections show up against the background.*"
962973
},
963974
"quarto.cells.background.delay": {
964975
"order": 22,

apps/vscode/src/providers/background.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ function clearEditorHighlightDecorations(editor: vscode.TextEditor) {
192192
editor.setDecorations(highlightingConfig.backgroundDecoration(), []);
193193
}
194194

195+
enum CellBackgroundColor {
196+
default = "default",
197+
off = "off",
198+
useTheme = "useTheme",
199+
}
200+
195201
class HiglightingConfig {
196202
constructor() { }
197203

@@ -213,10 +219,18 @@ class HiglightingConfig {
213219

214220
public sync() {
215221
const config = vscode.workspace.getConfiguration("quarto");
216-
const light = config.get("cells.background.light", "#E1E1E166");
217-
const dark = config.get("cells.background.dark", "#40404066");
222+
const backgroundOption = config.get<CellBackgroundColor>("cells.background.color", CellBackgroundColor.default);
223+
let light, dark;
224+
if (backgroundOption === CellBackgroundColor.useTheme) {
225+
const activeCellBackgroundThemeColor = new vscode.ThemeColor('notebook.selectedCellBackground');
226+
light = activeCellBackgroundThemeColor;
227+
dark = activeCellBackgroundThemeColor;
228+
} else {
229+
light = config.get<string>("cells.background.lightDefault", "#E1E1E166");
230+
dark = config.get<string>("cells.background.darkDefault", "#40404066");
231+
}
218232

219-
this.enabled_ = config.get("cells.background.enabled", true);
233+
this.enabled_ = backgroundOption !== CellBackgroundColor.off;
220234
this.delayMs_ = config.get("cells.background.delay", 250);
221235

222236

0 commit comments

Comments
 (0)