Skip to content

Commit 3c97285

Browse files
committed
Normalize property names in notebooks - remove _ on privates when possible
1 parent 8ba8383 commit 3c97285

File tree

3 files changed

+91
-90
lines changed

3 files changed

+91
-90
lines changed

src/vs/workbench/contrib/notebook/browser/notebookEditor.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export class NotebookEditor extends BaseEditor {
3131

3232
private readonly editorMemento: IEditorMemento<INotebookEditorViewState>;
3333
private readonly groupListener = this._register(new MutableDisposable());
34-
private readonly _widgetDisposableStore: DisposableStore = new DisposableStore();
35-
private _widget: IBorrowValue<NotebookEditorWidget> = { value: undefined };
36-
private _rootElement!: HTMLElement;
34+
private readonly widgetDisposableStore: DisposableStore = new DisposableStore();
35+
private widget: IBorrowValue<NotebookEditorWidget> = { value: undefined };
36+
private rootElement!: HTMLElement;
3737
private dimension?: DOM.Dimension;
3838

3939
// todo@rebornix is there a reason that `super.fireOnDidFocus` isn't used?
@@ -58,14 +58,14 @@ export class NotebookEditor extends BaseEditor {
5858
}
5959

6060
set viewModel(newModel: NotebookViewModel | undefined) {
61-
if (this._widget.value) {
62-
this._widget.value.viewModel = newModel;
61+
if (this.widget.value) {
62+
this.widget.value.viewModel = newModel;
6363
this._onDidChangeModel.fire();
6464
}
6565
}
6666

6767
get viewModel() {
68-
return this._widget.value?.viewModel;
68+
return this.widget.value?.viewModel;
6969
}
7070

7171
get minimumWidth(): number { return 375; }
@@ -82,26 +82,26 @@ export class NotebookEditor extends BaseEditor {
8282
}
8383

8484
protected createEditor(parent: HTMLElement): void {
85-
this._rootElement = DOM.append(parent, DOM.$('.notebook-editor'));
85+
this.rootElement = DOM.append(parent, DOM.$('.notebook-editor'));
8686

8787
// this._widget.createEditor();
88-
this._register(this.onDidFocus(() => this._widget.value?.updateEditorFocus()));
89-
this._register(this.onDidBlur(() => this._widget.value?.updateEditorFocus()));
88+
this._register(this.onDidFocus(() => this.widget.value?.updateEditorFocus()));
89+
this._register(this.onDidBlur(() => this.widget.value?.updateEditorFocus()));
9090
}
9191

9292
getDomNode() {
93-
return this._rootElement;
93+
return this.rootElement;
9494
}
9595

9696
getControl(): NotebookEditorWidget | undefined {
97-
return this._widget.value;
97+
return this.widget.value;
9898
}
9999

100100
onWillHide() {
101101
this.saveEditorViewState(this.input);
102-
if (this.input && this._widget.value) {
102+
if (this.input && this.widget.value) {
103103
// the widget is not transfered to other editor inputs
104-
this._widget.value.onWillHide();
104+
this.widget.value.onWillHide();
105105
}
106106
super.onWillHide();
107107
}
@@ -113,7 +113,7 @@ export class NotebookEditor extends BaseEditor {
113113

114114
focus() {
115115
super.focus();
116-
this._widget.value?.focus();
116+
this.widget.value?.focus();
117117
}
118118

119119
async setInput(input: NotebookEditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise<void> {
@@ -123,21 +123,21 @@ export class NotebookEditor extends BaseEditor {
123123
this.saveEditorViewState(this.input);
124124
await super.setInput(input, options, token);
125125

126-
this._widgetDisposableStore.clear();
126+
this.widgetDisposableStore.clear();
127127

128128
// there currently is a widget which we still own so
129129
// we need to hide it before getting a new widget
130-
if (this._widget.value) {
131-
this._widget.value.onWillHide();
130+
if (this.widget.value) {
131+
this.widget.value.onWillHide();
132132
}
133133

134-
this._widget = this.instantiationService.invokeFunction(this.notebookWidgetService.retrieveWidget, group, input);
134+
this.widget = this.instantiationService.invokeFunction(this.notebookWidgetService.retrieveWidget, group, input);
135135

136136
if (this.dimension) {
137-
this._widget.value!.layout(this.dimension, this._rootElement);
137+
this.widget.value!.layout(this.dimension, this.rootElement);
138138
}
139139

140-
const model = await input.resolve(this._widget.value!.getId());
140+
const model = await input.resolve(this.widget.value!.getId());
141141

142142
if (model === null) {
143143
this.notificationService.prompt(
@@ -157,19 +157,19 @@ export class NotebookEditor extends BaseEditor {
157157

158158
const viewState = this.loadTextEditorViewState(input);
159159

160-
await this._widget.value!.setModel(model.notebook, viewState, options);
161-
this._widgetDisposableStore.add(this._widget.value!.onDidFocus(() => this._onDidFocusWidget.fire()));
160+
await this.widget.value!.setModel(model.notebook, viewState, options);
161+
this.widgetDisposableStore.add(this.widget.value!.onDidFocus(() => this._onDidFocusWidget.fire()));
162162

163163
if (this.editorGroupService instanceof EditorPart) {
164-
this._widgetDisposableStore.add(this.editorGroupService.createEditorDropTarget(this._widget.value!.getDomNode(), {
164+
this.widgetDisposableStore.add(this.editorGroupService.createEditorDropTarget(this.widget.value!.getDomNode(), {
165165
groupContainsPredicate: (group) => this.group?.id === group.group.id
166166
}));
167167
}
168168
}
169169

170170
clearInput(): void {
171-
if (this._widget.value) {
172-
this._widget.value.onWillHide();
171+
if (this.widget.value) {
172+
this.widget.value.onWillHide();
173173
}
174174
super.clearInput();
175175
}
@@ -181,8 +181,8 @@ export class NotebookEditor extends BaseEditor {
181181
}
182182

183183
private saveEditorViewState(input: IEditorInput | undefined): void {
184-
if (this.group && this._widget.value && input instanceof NotebookEditorInput) {
185-
const state = this._widget.value.getEditorViewState();
184+
if (this.group && this.widget.value && input instanceof NotebookEditorInput) {
185+
const state = this.widget.value.getEditorViewState();
186186
this.editorMemento.saveEditorState(this.group, input.resource, state);
187187
}
188188
}
@@ -196,15 +196,15 @@ export class NotebookEditor extends BaseEditor {
196196
}
197197

198198
layout(dimension: DOM.Dimension): void {
199-
this._rootElement.classList.toggle('mid-width', dimension.width < 1000 && dimension.width >= 600);
200-
this._rootElement.classList.toggle('narrow-width', dimension.width < 600);
199+
this.rootElement.classList.toggle('mid-width', dimension.width < 1000 && dimension.width >= 600);
200+
this.rootElement.classList.toggle('narrow-width', dimension.width < 600);
201201
this.dimension = dimension;
202202

203-
if (!this._widget.value || !(this._input instanceof NotebookEditorInput)) {
203+
if (!this.widget.value || !(this._input instanceof NotebookEditorInput)) {
204204
return;
205205
}
206206

207-
if (this._input.resource.toString() !== this._widget.value.viewModel?.uri.toString() && this._widget.value?.viewModel) {
207+
if (this._input.resource.toString() !== this.widget.value.viewModel?.uri.toString() && this.widget.value?.viewModel) {
208208
// input and widget mismatch
209209
// this happens when
210210
// 1. open document A, pin the document
@@ -214,7 +214,7 @@ export class NotebookEditor extends BaseEditor {
214214
return;
215215
}
216216

217-
this._widget.value.layout(this.dimension, this._rootElement);
217+
this.widget.value.layout(this.dimension, this.rootElement);
218218
}
219219

220220
//#endregion

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
9090
private editorExecutingNotebook: IContextKey<boolean> | null = null;
9191
private notebookHasMultipleKernels: IContextKey<boolean> | null = null;
9292
private outputRenderer: OutputRenderer;
93-
protected readonly _contributions: { [key: string]: INotebookEditorContribution; };
93+
protected readonly contributions: { [key: string]: INotebookEditorContribution; };
9494
private scrollBeyondLastLine: boolean;
9595
private readonly memento: Memento;
96+
private readonly onDidFocusEmitter = this._register(new Emitter<void>());
97+
public readonly onDidFocus = this.onDidFocusEmitter.event;
98+
private cellContextKeyManager: CellContextKeyManager | null = null;
99+
private isVisible = false;
100+
private readonly uuid = generateUuid();
101+
96102
private _isDisposed: boolean = false;
97-
private readonly _onDidFocusWidget = this._register(new Emitter<void>());
98-
public get onDidFocus(): Event<any> { return this._onDidFocusWidget.event; }
99-
private _cellContextKeyManager: CellContextKeyManager | null = null;
100-
private _isVisible = false;
101-
private readonly _uuid = generateUuid();
102103

103104
get isDisposed() {
104105
return this._isDisposed;
@@ -110,19 +111,19 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
110111
@INotebookService private notebookService: INotebookService,
111112
@IConfigurationService private readonly configurationService: IConfigurationService,
112113
@IContextKeyService readonly contextKeyService: IContextKeyService,
113-
@ILayoutService private readonly _layoutService: ILayoutService
114+
@ILayoutService private readonly layoutService: ILayoutService
114115
) {
115116
super();
116117
this.memento = new Memento(NotebookEditorWidget.ID, storageService);
117118

118119
this.outputRenderer = new OutputRenderer(this, this.instantiationService);
119-
this._contributions = {};
120+
this.contributions = {};
120121
this.scrollBeyondLastLine = this.configurationService.getValue<boolean>('editor.scrollBeyondLastLine');
121122

122123
this.configurationService.onDidChangeConfiguration(e => {
123124
if (e.affectsConfiguration('editor.scrollBeyondLastLine')) {
124125
this.scrollBeyondLastLine = this.configurationService.getValue<boolean>('editor.scrollBeyondLastLine');
125-
if (this.dimension && this._isVisible) {
126+
if (this.dimension && this.isVisible) {
126127
this.layout(this.dimension);
127128
}
128129
}
@@ -132,7 +133,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
132133
}
133134

134135
public getId(): string {
135-
return this._uuid;
136+
return this.uuid;
136137
}
137138

138139
private readonly _onDidChangeModel = new Emitter<NotebookTextModel | undefined>();
@@ -231,12 +232,12 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
231232
DOM.addClass(this.overlayContainer, 'notebook-editor');
232233
this.overlayContainer.style.visibility = 'hidden';
233234

234-
this._layoutService.container.appendChild(this.overlayContainer);
235+
this.layoutService.container.appendChild(this.overlayContainer);
235236
this.createBody(this.overlayContainer);
236237
this.generateFontInfo();
237238
this.editorFocus = NOTEBOOK_EDITOR_FOCUSED.bindTo(this.contextKeyService);
238239
this.editorFocus.set(true);
239-
this._isVisible = true;
240+
this.isVisible = true;
240241
this.outputFocus = NOTEBOOK_OUTPUT_FOCUSED.bindTo(this.contextKeyService);
241242
this.editorEditable = NOTEBOOK_EDITOR_EDITABLE.bindTo(this.contextKeyService);
242243
this.editorEditable.set(true);
@@ -251,7 +252,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
251252
for (const desc of contributions) {
252253
try {
253254
const contribution = this.instantiationService.createInstance(desc.ctor, this);
254-
this._contributions[desc.id] = contribution;
255+
this.contributions[desc.id] = contribution;
255256
} catch (err) {
256257
onUnexpectedError(err);
257258
}
@@ -364,15 +365,15 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
364365

365366
const widgetFocusTracker = DOM.trackFocus(this.getDomNode());
366367
this._register(widgetFocusTracker);
367-
this._register(widgetFocusTracker.onDidFocus(() => this._onDidFocusWidget.fire()));
368+
this._register(widgetFocusTracker.onDidFocus(() => this.onDidFocusEmitter.fire()));
368369
}
369370

370371
getDomNode() {
371372
return this.overlayContainer;
372373
}
373374

374375
onWillHide() {
375-
this._isVisible = false;
376+
this.isVisible = false;
376377
this.editorFocus?.set(false);
377378
this.overlayContainer.style.visibility = 'hidden';
378379
this.overlayContainer.style.left = '-50000px';
@@ -383,7 +384,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
383384
}
384385

385386
focus() {
386-
this._isVisible = true;
387+
this.isVisible = true;
387388
this.editorFocus?.set(true);
388389
this.list?.domFocus();
389390
this._onDidFocusEditorWidget.fire();
@@ -398,22 +399,22 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
398399
// clear state
399400
this.dndController?.clearGlobalDragState();
400401

401-
this._setKernels(textModel);
402+
this.setKernels(textModel);
402403

403404
this.localStore.add(this.notebookService.onDidChangeKernels(() => {
404405
if (this.activeKernel === undefined) {
405-
this._setKernels(textModel);
406+
this.setKernels(textModel);
406407
}
407408
}));
408409

409410
this.localStore.add(this.list!.onDidChangeFocus(() => {
410411
const focused = this.list!.getFocusedElements()[0];
411412
if (focused) {
412-
if (!this._cellContextKeyManager) {
413-
this._cellContextKeyManager = this.localStore.add(new CellContextKeyManager(this.contextKeyService, textModel, focused as any));
413+
if (!this.cellContextKeyManager) {
414+
this.cellContextKeyManager = this.localStore.add(new CellContextKeyManager(this.contextKeyService, textModel, focused as any));
414415
}
415416

416-
this._cellContextKeyManager.updateForElement(focused as any);
417+
this.cellContextKeyManager.updateForElement(focused as any);
417418
}
418419
}));
419420

@@ -472,7 +473,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
472473
this.list?.clear();
473474
}
474475

475-
private _setKernels(textModel: NotebookTextModel) {
476+
private setKernels(textModel: NotebookTextModel) {
476477
const provider = this.notebookService.getContributedNotebookProviders(this.viewModel!.uri)[0];
477478
const availableKernels = this.notebookService.getContributedNotebookKernels(textModel.viewType, textModel.uri);
478479

@@ -522,7 +523,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
522523
this.webview.webview.onDidFocus(() => {
523524
this.outputFocus?.set(true);
524525
this.updateEditorFocus();
525-
this._onDidFocusWidget.fire();
526+
this.onDidFocusEmitter.fire();
526527
});
527528

528529
this.localStore.add(this.webview.onMessage(message => {
@@ -553,10 +554,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
553554
// contribution state restore
554555

555556
const contributionsState = viewState?.contributionsState || {};
556-
const keys = Object.keys(this._contributions);
557+
const keys = Object.keys(this.contributions);
557558
for (let i = 0, len = keys.length; i < len; i++) {
558559
const id = keys[i];
559-
const contribution = this._contributions[id];
560+
const contribution = this.contributions[id];
560561
if (typeof contribution.restoreViewState === 'function') {
561562
contribution.restoreViewState(contributionsState[id]);
562563
}
@@ -696,9 +697,9 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
696697
// Save contribution view states
697698
const contributionsState: { [key: string]: any } = {};
698699

699-
const keys = Object.keys(this._contributions);
700+
const keys = Object.keys(this.contributions);
700701
for (const id of keys) {
701-
const contribution = this._contributions[id];
702+
const contribution = this.contributions[id];
702703
if (typeof contribution.saveViewState === 'function') {
703704
contributionsState[id] = contribution.saveViewState();
704705
}
@@ -1218,18 +1219,18 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
12181219

12191220
//#region Editor Contributions
12201221
public getContribution<T extends INotebookEditorContribution>(id: string): T {
1221-
return <T>(this._contributions[id] || null);
1222+
return <T>(this.contributions[id] || null);
12221223
}
12231224

12241225
//#endregion
12251226

12261227
dispose() {
12271228
this._isDisposed = true;
12281229
this.notebookService.removeNotebookEditor(this);
1229-
const keys = Object.keys(this._contributions);
1230+
const keys = Object.keys(this.contributions);
12301231
for (let i = 0, len = keys.length; i < len; i++) {
12311232
const contributionId = keys[i];
1232-
this._contributions[contributionId].dispose();
1233+
this.contributions[contributionId].dispose();
12331234
}
12341235

12351236
this.localStore.clear();

0 commit comments

Comments
 (0)