diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 2379c1c4eb6..c0629a4b92c 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -13,7 +13,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle'; import { readonly } from 'vs/base/common/errors'; import { Emitter, Event } from 'vs/base/common/event'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; -import { INotebookDisplayOrder, IGenericOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { INotebookDisplayOrder, IGenericOutput, parseCellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { ISplice } from 'vs/base/common/sequence'; interface ExtHostOutputDisplayOrder { @@ -421,21 +421,25 @@ export class ExtHostNotebookEditor implements vscode.NotebookEditor { public document: ExtHostNotebookDocument, private _documentsAndEditors: ExtHostDocumentsAndEditors ) { - let regex = new RegExp(`notebook\\+${viewType}-(\\d+)-(\\d+)`); + const regex = new RegExp(/cell_(\d)*\./g); this._documentsAndEditors.onDidAddDocuments(documents => { for (const data of documents) { let textDocument = data.document; - let authority = textDocument.uri.authority; + let parsedCellUri = parseCellUri(textDocument.uri); - if (authority !== '') { - let matches = regex.exec(authority); - if (matches) { - const notebookHandle = matches[1]; - const cellHandle = matches[2]; + if (!parsedCellUri) { + continue; + } - if (Number(notebookHandle) === this.document.handle) { - document.attachCellTextDocument(Number(cellHandle), textDocument); - } + let notebookUri = parsedCellUri.notebook; + let cellFsPath = textDocument.uri.fsPath; + + let matches = regex.exec(cellFsPath); + + if (matches) { + const cellHandle = matches[1]; + if (this.document.uri.fsPath === notebookUri.fsPath) { + document.attachCellTextDocument(Number(cellHandle), textDocument); } } } @@ -444,17 +448,21 @@ export class ExtHostNotebookEditor implements vscode.NotebookEditor { this._documentsAndEditors.onDidRemoveDocuments(documents => { for (const data of documents) { let textDocument = data.document; - let authority = textDocument.uri.authority; + let parsedCellUri = parseCellUri(textDocument.uri); - if (authority !== '') { - let matches = regex.exec(authority); - if (matches) { - const notebookHandle = matches[1]; - const cellHandle = matches[2]; + if (!parsedCellUri) { + continue; + } - if (Number(notebookHandle) === this.document.handle) { - document.detachCellTextDocument(Number(cellHandle), textDocument); - } + let notebookUri = parsedCellUri.notebook; + let cellFsPath = textDocument.uri.fsPath; + + let matches = regex.exec(cellFsPath); + + if (matches) { + const cellHandle = matches[1]; + if (this.document.uri.fsPath === notebookUri.fsPath) { + document.detachCellTextDocument(Number(cellHandle), textDocument); } } } diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index a074de0165f..2b9e09629bf 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -16,7 +16,7 @@ import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchCo import { IEditorInput, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions, IEditorInputFactory, EditorInput } from 'vs/workbench/common/editor'; import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor'; import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput'; -import { INotebookService, NotebookService, parseCellUri } from 'vs/workbench/contrib/notebook/browser/notebookService'; +import { INotebookService, NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService'; import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService'; import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService'; @@ -36,6 +36,7 @@ import 'vs/workbench/contrib/notebook/browser/output/transforms/richTransform'; // Actions import 'vs/workbench/contrib/notebook/browser/notebookActions'; +import { parseCellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon'; Registry.as(EditorExtensions.Editors).registerEditor( EditorDescriptor.create( diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index b17696270cf..54d1f0494b6 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -23,12 +23,12 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; import { EditorOptions, IEditorMemento, ICompositeCodeEditor } from 'vs/workbench/common/editor'; import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { NotebookEditorInput, NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput'; -import { INotebookService, parseCellUri } from 'vs/workbench/contrib/notebook/browser/notebookService'; +import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService'; import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/output/outputRenderer'; import { BackLayerWebView } from 'vs/workbench/contrib/notebook/browser/renderers/backLayerWebView'; import { CodeCellRenderer, MarkdownCellRenderer, NotebookCellListDelegate } from 'vs/workbench/contrib/notebook/browser/renderers/cellRenderer'; import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/renderers/cellViewModel'; -import { CELL_MARGIN, INotebook, NotebookCellsSplice, IOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { CELL_MARGIN, INotebook, NotebookCellsSplice, IOutput, parseCellUri } 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'; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookService.ts b/src/vs/workbench/contrib/notebook/browser/notebookService.ts index 73178e55cf0..c6516ab056d 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookService.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookService.ts @@ -12,17 +12,6 @@ import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.pr import { Emitter, Event } from 'vs/base/common/event'; import { INotebook, ICell, INotebookMimeTypeSelector } from 'vs/workbench/contrib/notebook/common/notebookCommon'; -export function parseCellUri(resource: URI): { viewType: string, notebook: URI } | undefined { - //vscode-notebook:///cell_.ext - if (resource.scheme !== 'vscode-notebook') { - return undefined; - } - // @todo Jo,Peng: `authority` will be transformed to lower case in `URI.toString()`, so we won't retrive the same viewType later on. - const viewType = resource.authority; - const notebook = URI.parse(resource.query); - return { viewType, notebook }; -} - function MODEL_ID(resource: URI): string { return resource.toString(); } diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 0221991fab0..c913dfe1c64 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -164,3 +164,14 @@ export type NotebookCellOutputsSplice = [ number /* delete count */, IOutput[] ]; + +export function parseCellUri(resource: URI): { viewType: string, notebook: URI } | undefined { + //vscode-notebook:///cell_.ext + if (resource.scheme !== 'vscode-notebook') { + return undefined; + } + // @todo Jo,Peng: `authority` will be transformed to lower case in `URI.toString()`, so we won't retrive the same viewType later on. + const viewType = resource.authority; + const notebook = URI.parse(resource.query); + return { viewType, notebook }; +}