diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index e9d8921cfca85e3fe85dacc2684e2d5c3b881d33..f7ccc4da432076d3bf2308859a14471ef2946dbc 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -165,7 +165,6 @@ export interface ICompositeCodeEditor { readonly onDidChangeActiveEditor: Event; readonly activeCodeEditor: IEditor | undefined; // readonly editors: readonly ICodeEditor[] maybe supported with uris - activate(input: IResourceEditorInput): IEditor | undefined; } export namespace ICompositeCodeEditor { @@ -173,8 +172,7 @@ export namespace ICompositeCodeEditor { if (!thing || typeof thing !== 'object') { return false; } - return typeof (thing).activate === 'function' - && typeof (thing).onDidChangeActiveEditor === 'function'; + return typeof (thing).onDidChangeActiveEditor === 'function'; } } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index 8305cfbcc7c8daf2c4d0b0bf87ce023dcde7c764..b8638f9a4d995042f10769a8517a7072bdaaa78d 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -27,7 +27,7 @@ import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebook import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer'; import { BackLayerWebView } from 'vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView'; import { CodeCellRenderer, MarkdownCellRenderer, NotebookCellListDelegate } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer'; -import { CELL_MARGIN, NotebookCellsSplice, IOutput, parseCellUri, CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { CELL_MARGIN, NotebookCellsSplice, IOutput, CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { IWebviewService } from 'vs/workbench/contrib/webview/browser/webview'; import { getExtraColor } from 'vs/workbench/contrib/welcome/walkThrough/common/walkThroughUtils'; import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -40,6 +40,7 @@ import { NotebookFindWidget } from 'vs/workbench/contrib/notebook/browser/contri import { NotebookViewModel, INotebookEditorViewState, IModelDecorationsChangeAccessor } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel'; import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor'; import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel'; +import { isEqual } from 'vs/base/common/resources'; const $ = DOM.$; const NOTEBOOK_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'NotebookEditorViewState'; @@ -85,40 +86,6 @@ export class NotebookCodeEditors implements ICompositeCodeEditor { ? this._renderedEditors.get(focused) : undefined; } - - activate(input: IResourceEditorInput): ICodeEditor | undefined { - const data = parseCellUri(input.resource); - if (!data) { - return undefined; - } - // find the CellViewModel which represents the cell with the - // given uri, scroll it into view so that the editor is alive, - // and then set selection et al.. - for (let i = 0; i < this._list.length; i++) { - const item = this._list.element(i); - if (item.cell.uri.toString() === input.resource.toString()) { - this._list.reveal(i, 0.2); - this._list.setFocus([i]); - const editor = this._renderedEditors.get(item); - if (!editor) { - break; - } - if (input.options?.selection) { - const { selection } = input.options; - editor.setSelection({ - ...selection, - endLineNumber: selection.endLineNumber || selection.startLineNumber, - endColumn: selection.endColumn || selection.startColumn - }); - } - if (!input.options?.preserveFocus) { - editor.focus(); - } - return editor; - } - } - return undefined; - } } export class NotebookEditor extends BaseEditor implements INotebookEditor { @@ -312,9 +279,26 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { await this.attachModel(input, model); } - if (options instanceof NotebookEditorOptions) { - if (options.cellOptions) { - this.control?.activate(options.cellOptions); + // reveal cell if editor options tell to do so + if (options instanceof NotebookEditorOptions && options.cellOptions) { + const cellOptions = options.cellOptions; + const cell = this.notebookViewModel!.viewCells.find(cell => isEqual(cell.cell.uri, cellOptions.resource)); + if (cell && this.renderedEditors.has(cell)) { + this.revealInCenterIfOutsideViewport(cell); + const editor = this.renderedEditors.get(cell)!; + if (editor) { + if (cellOptions.options?.selection) { + const { selection } = cellOptions.options; + editor.setSelection({ + ...selection, + endLineNumber: selection.endLineNumber || selection.startLineNumber, + endColumn: selection.endColumn || selection.startColumn + }); + } + if (!cellOptions.options?.preserveFocus) { + editor.focus(); + } + } } } } diff --git a/src/vs/workbench/services/editor/browser/codeEditorService.ts b/src/vs/workbench/services/editor/browser/codeEditorService.ts index 1add57181fc0e4d6dccd872203fa0c0340676cd8..687e55477fd7c847388b55af6adae79ca43feb13 100644 --- a/src/vs/workbench/services/editor/browser/codeEditorService.ts +++ b/src/vs/workbench/services/editor/browser/codeEditorService.ts @@ -63,15 +63,6 @@ export class CodeEditorService extends CodeEditorServiceImpl { return targetEditor; } - // CompositeCodeEditor - const control = this.editorService.activeEditorPane?.getControl(); - if (ICompositeCodeEditor.is(control)) { - const editor = control.activate(input); - if (isCodeEditor(editor)) { - return editor; - } - } - // Open using our normal editor service return this.doOpenCodeEditor(input, source, sideBySide); }