Skip to content

Commit dada212

Browse files
authored
Fix current cell colors again (microsoft#5403)
* Make a box instead of a background * Fix casing on IPython * Final decision on decorator * Code cleanup * Update in between color to be an editor color
1 parent 1122cd3 commit dada212

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

package.nls.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
"python.command.python.datascience.undocells.title": "Undo last Python Interactive action",
5050
"python.command.python.datascience.redocells.title": "Redo last Python Interactive action",
5151
"python.command.python.datascience.removeallcells.title": "Delete all Python Interactive cells",
52-
"python.command.python.datascience.interruptkernel.title": "Interrupt iPython Kernel",
53-
"python.command.python.datascience.restartkernel.title": "Restart iPython Kernel",
52+
"python.command.python.datascience.interruptkernel.title": "Interrupt IPython Kernel",
53+
"python.command.python.datascience.restartkernel.title": "Restart IPython Kernel",
5454
"python.command.python.datascience.expandallcells.title": "Expand all Python Interactive cells",
5555
"python.command.python.datascience.collapseallcells.title": "Collapse all Python Interactive cells",
5656
"python.snippet.launch.standard.label": "Python: Current File",
@@ -100,7 +100,7 @@
100100
"Interpreters.LoadingInterpreters": "Loading Python Interpreters",
101101
"Common.doNotShowAgain": "Do not show again",
102102
"Interpreters.environmentPromptMessage": "We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?",
103-
"DataScience.restartKernelMessage": "Do you want to restart the iPython kernel? All variables will be lost.",
103+
"DataScience.restartKernelMessage": "Do you want to restart the IPython kernel? All variables will be lost.",
104104
"DataScience.restartKernelMessageYes": "Restart",
105105
"DataScience.restartKernelMessageNo": "Cancel",
106106
"DataScience.restartingKernelFailed": "Kernel restart failed. Jupyter server is hung. Please reload VS Code.",
@@ -111,12 +111,12 @@
111111
"InteractiveShiftEnterBanner.bannerMessage": "Would you like to run code in the 'Python Interactive' window (an IPython console) for 'shift-enter'? Select 'No' to continue to run code in the Python Terminal. This can be changed later in settings.",
112112
"InteractiveShiftEnterBanner.bannerLabelYes": "Yes",
113113
"InteractiveShiftEnterBanner.bannerLabelNo": "No",
114-
"DataScience.restartingKernelStatus": "Restarting iPython Kernel",
114+
"DataScience.restartingKernelStatus": "Restarting IPython Kernel",
115115
"DataScience.executingCode": "Executing Cell",
116116
"DataScience.collapseAll": "Collapse all cell inputs",
117117
"DataScience.expandAll": "Expand all cell inputs",
118118
"DataScience.export": "Export as Jupyter Notebook",
119-
"DataScience.restartServer": "Restart iPython Kernel",
119+
"DataScience.restartServer": "Restart IPython Kernel",
120120
"DataScience.undo": "Undo",
121121
"DataScience.redo": "Redo",
122122
"DataScience.clearAll": "Remove All Cells",
@@ -161,13 +161,13 @@
161161
"diagnostics.yesUpdateLaunch": "Yes, update launch.json",
162162
"diagnostics.bannerLabelNo": "No, I will do it later",
163163
"diagnostics.invalidTestSettings": "Your settings needs to be updated to change the setting \"python.unitTest.\" to \"python.testing.\", otherwise testing Python code using the extension may not work. Would you like to automatically update your settings now?",
164-
"DataScience.interruptKernel": "Interrupt iPython Kernel",
164+
"DataScience.interruptKernel": "Interrupt IPython Kernel",
165165
"DataScience.exportingFormat": "Exporting {0}",
166166
"DataScience.exportCancel": "Cancel",
167167
"Common.canceled": "Canceled",
168168
"DataScience.importChangeDirectoryComment": "#%% Change working directory from the workspace root to the ipynb file location. Turn this addition off with the DataScience.changeDirOnImportExport setting",
169169
"DataScience.exportChangeDirectoryComment": "# Change directory to VSCode workspace root so that relative path loads work correctly. Turn this addition off with the DataScience.changeDirOnImportExport setting",
170-
"DataScience.interruptKernelStatus": "Interrupting iPython Kernel",
170+
"DataScience.interruptKernelStatus": "Interrupting IPython Kernel",
171171
"DataScience.restartKernelAfterInterruptMessage": "Interrupting the kernel timed out. Do you want to restart the kernel instead? All variables will be lost.",
172172
"DataScience.pythonInterruptFailedHeader": "Keyboard interrupt crashed the kernel. Kernel restarted.",
173173
"DataScience.sysInfoURILabel": "Jupyter Server URI: ",

src/client/datascience/editor-integration/decorator.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,16 @@ import { generateCellRanges } from '../cellFactory';
1313
@injectable()
1414
export class Decorator implements IExtensionActivationService, IDisposable {
1515

16-
private activeCellType: vscode.TextEditorDecorationType;
17-
private cellSeparatorType: vscode.TextEditorDecorationType;
16+
private activeCellTop: vscode.TextEditorDecorationType | undefined;
17+
private activeCellBottom: vscode.TextEditorDecorationType | undefined;
18+
private cellSeparatorType: vscode.TextEditorDecorationType | undefined;
1819
private timer: NodeJS.Timer | undefined;
1920

2021
constructor(@inject(IDocumentManager) private documentManager: IDocumentManager,
2122
@inject(IDisposableRegistry) disposables: IDisposableRegistry,
2223
@inject(IConfigurationService) private configuration: IConfigurationService)
2324
{
24-
this.activeCellType = this.documentManager.createTextEditorDecorationType({
25-
backgroundColor: new vscode.ThemeColor('peekViewEditor.background'),
26-
isWholeLine: true
27-
});
28-
this.cellSeparatorType = this.documentManager.createTextEditorDecorationType({
29-
borderColor: new vscode.ThemeColor('peekViewEditor.background'),
30-
borderWidth: '1px 0px 0px 0px',
31-
borderStyle: 'solid',
32-
isWholeLine: true
33-
});
25+
this.computeDecorations();
3426
disposables.push(this);
3527
disposables.push(this.configuration.getSettings().onDidChange(this.settingsChanged, this));
3628
disposables.push(this.documentManager.onDidChangeActiveTextEditor(this.changedEditor, this));
@@ -80,22 +72,48 @@ export class Decorator implements IExtensionActivationService, IDisposable {
8072
this.timer = setTimeout(() => this.update(editor), 100);
8173
}
8274

75+
private computeDecorations() {
76+
this.activeCellTop = this.documentManager.createTextEditorDecorationType({
77+
borderColor: new vscode.ThemeColor('peekView.border'),
78+
borderWidth: '2px 0px 0px 0px',
79+
borderStyle: 'solid',
80+
isWholeLine: true
81+
});
82+
this.activeCellBottom = this.documentManager.createTextEditorDecorationType({
83+
borderColor: new vscode.ThemeColor('peekView.border'),
84+
borderWidth: '0px 0px 1px 0px',
85+
borderStyle: 'solid',
86+
isWholeLine: true
87+
});
88+
this.cellSeparatorType = this.documentManager.createTextEditorDecorationType({
89+
borderColor: new vscode.ThemeColor('editor.lineHighlightBorder'),
90+
borderWidth: '1px 0px 0px 0px',
91+
borderStyle: 'solid',
92+
isWholeLine: true
93+
});
94+
}
95+
8396
private update(editor: vscode.TextEditor | undefined) {
84-
if (editor && editor.document && editor.document.languageId === PYTHON_LANGUAGE) {
97+
if (editor && editor.document && editor.document.languageId === PYTHON_LANGUAGE &&
98+
this.activeCellTop && this.cellSeparatorType && this.activeCellBottom) {
8599
const settings = this.configuration.getSettings().datascience;
86100
if (settings.decorateCells && settings.enabled) {
87101
// Find all of the cells
88102
const cells = generateCellRanges(editor.document, this.configuration.getSettings().datascience);
89103

90104
// Find the range for our active cell.
91-
const activeRanges = cells.map(c => c.range).filter(r => r.contains(editor.selection.anchor));
92-
editor.setDecorations(this.activeCellType, activeRanges);
105+
const currentRange = cells.map(c => c.range).filter(r => r.contains(editor.selection.anchor));
106+
const rangeTop = currentRange.length > 0 ? [new vscode.Range(currentRange[0].start, currentRange[0].start)] : [];
107+
const rangeBottom = currentRange.length > 0 ? [new vscode.Range(currentRange[0].end, currentRange[0].end)] : [];
108+
editor.setDecorations(this.activeCellTop, rangeTop);
109+
editor.setDecorations(this.activeCellBottom, rangeBottom);
93110

94111
// Find the start range for the rest
95112
const startRanges = cells.map(c => new vscode.Range(c.range.start, c.range.start));
96113
editor.setDecorations(this.cellSeparatorType, startRanges);
97114
} else {
98-
editor.setDecorations(this.activeCellType, []);
115+
editor.setDecorations(this.activeCellTop, []);
116+
editor.setDecorations(this.activeCellBottom, []);
99117
editor.setDecorations(this.cellSeparatorType, []);
100118
}
101119
}

0 commit comments

Comments
 (0)