mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 18:48:33 -05:00
Books/fix relative links (#7083)
* fix to make relative links work on untitled notebooks * changes to make the preb/next links to work * show filename with extension
This commit is contained in:
@@ -276,7 +276,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
notebooks.push(notebook);
|
||||
this._allNotebooks.set(pathToNotebook, notebook);
|
||||
if (this._openAsUntitled) {
|
||||
this._allNotebooks.set(path.basename(pathToNotebook, '.ipynb'), notebook);
|
||||
this._allNotebooks.set(path.basename(pathToNotebook), notebook);
|
||||
}
|
||||
} else if (fs.existsSync(pathToMarkdown)) {
|
||||
let markdown = new BookTreeItem({
|
||||
@@ -307,7 +307,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
|
||||
getNavigation(uri: vscode.Uri): Thenable<azdata.nb.NavigationResult> {
|
||||
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<BookTreeIte
|
||||
public get tableOfContentPaths() {
|
||||
return this._tableOfContentPaths;
|
||||
}
|
||||
|
||||
getUntitledNotebookUri(resource: string): vscode.Uri {
|
||||
let title = this.findNextUntitledFileName(resource);
|
||||
let untitledFileName: vscode.Uri = vscode.Uri.parse(`untitled:${title}`);
|
||||
if (!this._allNotebooks.get(untitledFileName.fsPath)) {
|
||||
let untitledFileName: vscode.Uri;
|
||||
if (process.platform.indexOf('win') > -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user