From 6643b5e520ba705e23bbff11c8ca08e8377d4271 Mon Sep 17 00:00:00 2001 From: rebornix Date: Tue, 2 Mar 2021 11:22:39 -0800 Subject: [PATCH] de-dup: uri. --- .../api/browser/mainThreadNotebook.ts | 2 +- .../notebook/browser/contrib/coreActions.ts | 2 +- .../browser/contrib/status/editorStatus.ts | 4 +- .../notebook/browser/notebookBrowser.ts | 3 -- .../notebook/browser/notebookEditorWidget.ts | 42 ------------------- .../notebook/browser/notebookServiceImpl.ts | 2 +- .../contrib/notebook/common/notebookCommon.ts | 1 - .../notebook/test/testNotebookEditor.ts | 3 -- 8 files changed, 5 insertions(+), 54 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadNotebook.ts b/src/vs/workbench/api/browser/mainThreadNotebook.ts index 13af39163ca..602385a1e28 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebook.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebook.ts @@ -94,7 +94,7 @@ class DocumentAndEditorState { private static _asEditorAddData(add: IEditor): INotebookEditorAddData { return { id: add.getId(), - documentUri: add.uri!, + documentUri: add.textModel!.uri, selections: add.getSelections(), visibleRanges: add.visibleRanges }; diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts index 795d5389c70..30da3100f8d 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts @@ -140,7 +140,7 @@ function getWidgetFromUri(accessor: ServicesAccessor, uri: URI) { const editorId = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editorId => editorId.editor instanceof NotebookEditorInput && editorId.editor.resource?.toString() === uri.toString()); if (editorId) { - const widget = notebookWidgetService.widgets.find(widget => widget.textModel?.viewType === (editorId.editor as NotebookEditorInput).viewType && widget.uri?.toString() === editorId.editor.resource!.toString()); + const widget = notebookWidgetService.widgets.find(widget => widget.textModel?.viewType === (editorId.editor as NotebookEditorInput).viewType && widget.textModel?.uri.toString() === editorId.editor.resource!.toString()); if (widget && widget.hasModel()) { return widget; diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts b/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts index 59bfb295f19..4d9c9d1ca13 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/status/editorStatus.ts @@ -92,7 +92,7 @@ registerAction2(class extends Action2 { if (selectedKernel) { editor.activeKernel = selectedKernel; - return selectedKernel.resolve(editor.uri!, editor.getId(), tokenSource.token); + return selectedKernel.resolve(editor.textModel!.uri, editor.getId(), tokenSource.token); } else { picker.show(); } @@ -112,7 +112,7 @@ registerAction2(class extends Action2 { kernelProviderId: a.extension.value, run: async () => { editor.activeKernel = a; - a.resolve(editor.uri!, editor.getId(), tokenSource.token); + a.resolve(editor.textModel!.uri, editor.getId(), tokenSource.token); }, buttons: [{ iconClass: ThemeIcon.asClassName(configureKernelIcon), diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index a8253e56750..9763ca432d8 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -323,7 +323,6 @@ export interface INotebookEditorCreationOptions { export interface IActiveNotebookEditor extends INotebookEditor { viewModel: NotebookViewModel; - uri: URI; // selection is never undefined when the editor is attached to a document. getSelection(): ICellRange; } @@ -354,8 +353,6 @@ export interface INotebookEditor extends IEditor, ICommonNotebookEditor { readonly onDidChangeAvailableKernels: Event; readonly onDidChangeKernel: Event; readonly onDidChangeActiveCell: Event; - readonly onDidScroll: Event; - isDisposed: boolean; getId(): string; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 189d4b18584..b4dfec119f9 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -15,7 +15,6 @@ import { onUnexpectedError } from 'vs/base/common/errors'; import { Emitter, Event } from 'vs/base/common/event'; import { combinedDisposable, Disposable, DisposableStore, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { extname } from 'vs/base/common/resources'; -import { ScrollEvent } from 'vs/base/common/scrollable'; import * as strings from 'vs/base/common/strings'; import { URI } from 'vs/base/common/uri'; import { generateUuid } from 'vs/base/common/uuid'; @@ -99,11 +98,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor private readonly _onDidFocusEmitter = this._register(new Emitter()); public readonly onDidFocus = this._onDidFocusEmitter.event; private readonly _insetModifyQueueByOutputId = new SequencerByKey(); - - set scrollTop(top: number) { - this._list.scrollTop = top; - } - private _kernelManger: NotebookEditorKernelManager; private _cellContextKeyManager: CellContextKeyManager | null = null; private _isVisible = false; @@ -131,10 +125,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor return this._notebookViewModel; } - get uri() { - return this._notebookViewModel?.uri; - } - get textModel() { return this._notebookViewModel?.notebookDocument; } @@ -178,11 +168,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor private readonly _onDidChangeActiveCell = this._register(new Emitter()); readonly onDidChangeActiveCell: Event = this._onDidChangeActiveCell.event; - - private readonly _onDidScroll = this._register(new Emitter()); - - readonly onDidScroll: Event = this._onDidScroll.event; - private _cursorNavigationMode: boolean = false; get cursorNavigationMode(): boolean { return this._cursorNavigationMode; @@ -544,10 +529,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor this.showListContextMenu(e); })); - this._register(this._list.onDidScroll((e) => { - this._onDidScroll.fire(e); - })); - this._register(this._list.onDidChangeVisibleRanges(() => { this._onDidChangeVisibleRanges.fire(); })); @@ -745,8 +726,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor this.viewModel?.dispose(); // avoid event this.viewModel = undefined; - // this.webview?.clearInsets(); - // this.webview?.clearPreloadsCache(); this._webview?.dispose(); this._webview?.element.remove(); this._webview = null; @@ -1086,15 +1065,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor return state; } - // private saveEditorViewState(input: NotebookEditorInput): void { - // if (this.group && this.notebookViewModel) { - // } - // } - - // private loadTextEditorViewState(): INotebookEditorViewState | undefined { - // return this.editorMemento.loadEditorState(this.group, input.resource); - // } - layout(dimension: DOM.Dimension, shadowElement?: HTMLElement): void { if (!shadowElement && this._shadowElementViewInfo === null) { this._dimension = dimension; @@ -1134,15 +1104,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor this._eventDispatcher?.emit([new NotebookLayoutChangedEvent({ width: true, fontInfo: true }, this.getLayoutInfo())]); } - - // protected saveState(): void { - // if (this.input instanceof NotebookEditorInput) { - // this.saveEditorViewState(this.input); - // } - - // super.saveState(); - // } - //#endregion //#region Editor Features @@ -1906,9 +1867,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor this._overlayContainer.remove(); this.viewModel?.dispose(); - - // this._layoutService.container.removeChild(this.overlayContainer); - super.dispose(); } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts index d4e63d0dabe..5dfe1a3350a 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts @@ -903,7 +903,7 @@ export class NotebookService extends Disposable implements INotebookService, IEd if (editor) { this._activeEditorDisposables.add(editor.onDidChangeKernel(() => { this._onDidChangeNotebookActiveKernel.fire({ - uri: editor.uri!, + uri: editor.textModel!.uri, providerHandle: editor.activeKernel?.providerHandle, kernelFriendlyId: editor.activeKernel?.friendlyId }); diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 9f087a7c51b..e3a06ba89dd 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -682,7 +682,6 @@ export interface IEditor extends editorCommon.ICompositeCodeEditor { getSelection(): ICellRange | undefined; getSelections(): ICellRange[]; visibleRanges: ICellRange[]; - uri?: URI; textModel?: NotebookTextModel; getId(): string; hasFocus(): boolean; diff --git a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts index ecc5b88ee46..26da2d77121 100644 --- a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts @@ -38,7 +38,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; -import { ScrollEvent } from 'vs/base/common/scrollable'; import { IFileStatWithMetadata } from 'vs/platform/files/common/files'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { NotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookCellList'; @@ -132,11 +131,9 @@ export class TestNotebookEditor implements INotebookEditor { multipleKernelsAvailable: boolean = false; onDidChangeAvailableKernels: Event = new Emitter().event; onDidChangeActiveCell: Event = new Emitter().event; - onDidScroll = new Emitter().event; onDidChangeVisibleRanges: Event = new Emitter().event; onDidChangeSelection: Event = new Emitter().event; visibleRanges: ICellRange[] = []; - uri?: URI | undefined; textModel?: NotebookTextModel | undefined; hasModel(): this is IActiveNotebookEditor {