diff --git a/extensions/notebook/src/book/bookTreeView.ts b/extensions/notebook/src/book/bookTreeView.ts index 5d5137f00a..58a7996d3b 100644 --- a/extensions/notebook/src/book/bookTreeView.ts +++ b/extensions/notebook/src/book/bookTreeView.ts @@ -276,7 +276,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider { - let notebook = this._allNotebooks.get(uri.fsPath); + let notebook = uri.scheme !== 'untitled' ? this._allNotebooks.get(uri.fsPath) : this._allNotebooks.get(path.basename(uri.fsPath)); let result: azdata.nb.NavigationResult; if (notebook) { result = { @@ -332,19 +332,25 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider -1) { + let title = path.join(path.dirname(resource), this.findNextUntitledFileName(resource)); + untitledFileName = vscode.Uri.parse(`untitled:${title}`); + } + else { + untitledFileName = vscode.Uri.parse(resource).with({ scheme: 'untitled' }); + } + if (!this._allNotebooks.get(untitledFileName.fsPath) && !this._allNotebooks.get(path.basename(untitledFileName.fsPath))) { let notebook = this._allNotebooks.get(resource); - this._allNotebooks.set(untitledFileName.fsPath, notebook); + this._allNotebooks.set(path.basename(untitledFileName.fsPath), notebook); } return untitledFileName; } findNextUntitledFileName(filePath: string): string { - const fileExtension = path.extname(filePath); - const baseName = path.basename(filePath, fileExtension); + const baseName = path.basename(filePath); let idx = 0; let title = `${baseName}`; do { diff --git a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts index 0443c40740..926950cf9f 100644 --- a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts @@ -707,8 +707,8 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements onNext: async (uri) => { let result = await this._proxy.$getNavigation(handle, uri); if (result) { - if (uri.scheme === Schemas.untitled) { - let untitledNbName: URI = URI.parse(`untitled:${path.basename(result.next.path, '.ipynb')}`); + if (result.next.scheme === Schemas.untitled) { + let untitledNbName: URI = URI.parse(`untitled:${path.basename(result.next.path)}`); this.doOpenEditor(untitledNbName, { initialContent: fs.readFileSync(result.next.path).toString(), initialDirtyState: false }); } else { @@ -719,8 +719,8 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements onPrevious: async (uri) => { let result = await this._proxy.$getNavigation(handle, uri); if (result) { - if (uri.scheme === Schemas.untitled) { - let untitledNbName: URI = URI.parse(`untitled:${path.basename(result.previous.path, '.ipynb')}`); + if (result.previous.scheme === Schemas.untitled) { + let untitledNbName: URI = URI.parse(`untitled:${path.basename(result.previous.path)}`); this.doOpenEditor(untitledNbName, { initialContent: fs.readFileSync(result.previous.path).toString(), initialDirtyState: false }); } else { diff --git a/src/sql/workbench/parts/notebook/electron-browser/outputs/notebookMarkdown.ts b/src/sql/workbench/parts/notebook/electron-browser/outputs/notebookMarkdown.ts index 5358c099a7..4bdd25e28f 100644 --- a/src/sql/workbench/parts/notebook/electron-browser/outputs/notebookMarkdown.ts +++ b/src/sql/workbench/parts/notebook/electron-browser/outputs/notebookMarkdown.ts @@ -226,6 +226,8 @@ export class NotebookMarkdownRenderer { return base.replace(/:[\s\S]*/, ':') + href; } else if (href.charAt(0) === '/') { return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href; + } else if (href.slice(0, 2) === '..') { + return path.join(base, href); } else { return base + href; }