Test/highlight correct nb (#11348)

* unit test of the method

* stash changes

* revealActiveDocumentInViewlet test

* separate tests

* test on activate

* added tests

* feedback changes

* naming change
This commit is contained in:
Maddy
2020-07-16 10:55:46 -07:00
committed by GitHub
parent b68b655fa5
commit 9b1eb53665
6 changed files with 185 additions and 52 deletions

View File

@@ -230,7 +230,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
}
}
async revealActiveDocumentInViewlet(uri?: vscode.Uri, shouldReveal: boolean = true): Promise<void> {
async revealActiveDocumentInViewlet(uri?: vscode.Uri, shouldReveal: boolean = true): Promise<BookTreeItem | undefined> {
let bookItem: BookTreeItem;
let notebookPath: string;
// If no uri is passed in, try to use the current active notebook editor
@@ -242,15 +242,16 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
} else if (uri.fsPath) {
notebookPath = uri.fsPath;
}
bookItem = notebookPath ? await this.findAndExpandParentNode(notebookPath) : undefined;
if (bookItem) {
if (shouldReveal || this._bookViewer.visible) {
bookItem = notebookPath ? await this.findAndExpandParentNode(notebookPath) : undefined;
// Select + focus item in viewlet if books viewlet is already open, or if we pass in variable
if (shouldReveal || this._bookViewer.visible) {
if (bookItem) {
// Note: 3 is the maximum number of levels that the vscode APIs let you expand to
await this._bookViewer.reveal(bookItem, { select: true, focus: true, expand: true });
}
}
return bookItem;
}
async findAndExpandParentNode(notebookPath: string): Promise<BookTreeItem> {
@@ -535,9 +536,4 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
}
return Promise.resolve(result);
}
public getBookFromItemPath(itemPath: string): BookModel | undefined {
let selectedBook = this.books.find(b => itemPath.toLowerCase().indexOf(b.bookPath.toLowerCase()) > -1);
return selectedBook;
}
}