fix search action (#14937)

* fix search action

* remove book version from book tree item
This commit is contained in:
Barbara Valdez
2021-04-01 11:16:32 -07:00
committed by GitHub
parent 37af88e265
commit a00ffa0469
4 changed files with 7 additions and 9 deletions

View File

@@ -316,7 +316,7 @@ export class BookTocManager implements IBookTocManager {
* @param section The section that's been moved.
* @param book The target book.
*/
async moveSectionFiles(section: BookTreeItem, book: BookTreeItem): Promise<void> {
async moveSectionFiles(section: BookTreeItem, bookItem: BookTreeItem): Promise<void> {
const uri = path.posix.join(path.posix.sep, path.relative(section.rootContentPath, section.book.contentPath));
let moveFile = path.join(path.parse(uri).dir, path.parse(uri).name);
let fileName = undefined;
@@ -349,9 +349,9 @@ export class BookTocManager implements IBookTocManager {
this.cleanUp(path.dirname(section.book.contentPath));
}
if (book.version === BookVersion.v1) {
if (bookItem.book.version === BookVersion.v1) {
// here we only convert if is v1 because we are already using the v2 notation for every book that we read.
this.newSection = convertTo(book.version, this.newSection);
this.newSection = convertTo(bookItem.book.version, this.newSection);
}
}
@@ -385,9 +385,9 @@ export class BookTocManager implements IBookTocManager {
fileName = fileName === undefined ? filePath.name : path.parse(fileName).name;
this.newSection.file = path.posix.join(path.posix.sep, fileName);
this.newSection.title = file.book.title;
if (book.version === BookVersion.v1) {
if (book.book.version === BookVersion.v1) {
// here we only convert if is v1 because we are already using the v2 notation for every book that we read.
this.newSection = convertTo(book.version, this.newSection);
this.newSection = convertTo(book.book.version, this.newSection);
}
}

View File

@@ -41,7 +41,6 @@ export class BookTreeItem extends vscode.TreeItem {
private _uri: string | undefined;
private _previousUri: string;
private _nextUri: string;
public readonly version: BookVersion;
public command: vscode.Command;
public resourceUri: vscode.Uri;
private _rootContentPath: string;
@@ -52,7 +51,6 @@ export class BookTreeItem extends vscode.TreeItem {
if (book.type === BookTreeItemType.Book) {
this.collapsibleState = book.treeItemCollapsibleState;
this._sections = book.page;
this.version = book.version;
if (book.isUntitled) {
this.contextValue = BookTreeItemType.providedBook;
} else {

View File

@@ -498,7 +498,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
public async searchJupyterBooks(treeItem?: BookTreeItem): Promise<void> {
let folderToSearch: string;
if (treeItem && treeItem.sections !== undefined) {
folderToSearch = treeItem.uri ? getContentPath(treeItem.version, treeItem.book.root, path.dirname(treeItem.uri)) : getContentPath(treeItem.version, treeItem.book.root, '');
folderToSearch = treeItem.uri ? getContentPath(treeItem.book.version, treeItem.book.root, path.dirname(treeItem.uri)) : getContentPath(treeItem.book.version, treeItem.book.root, '');
} else if (this.currentBook && !this.currentBook.isNotebook) {
folderToSearch = path.join(this.currentBook.contentFolderPath);
} else {

View File

@@ -28,7 +28,7 @@ export class BookTrustManager implements IBookTrustManager {
let trustableBookPaths = this.getTrustableBookPaths();
let hasTrustedBookPath: boolean = treeBookItems
.filter(bookItem => trustableBookPaths.some(trustableBookPath => trustableBookPath === path.join(bookItem.book.root, path.sep)))
.some(bookItem => normalizedNotebookUri.startsWith(bookItem.version === BookVersion.v1 ? path.join(bookItem.book.root, 'content', path.sep) : path.join(bookItem.book.root, path.sep)));
.some(bookItem => normalizedNotebookUri.startsWith(bookItem.book.version === BookVersion.v1 ? path.join(bookItem.book.root, 'content', path.sep) : path.join(bookItem.book.root, path.sep)));
let isNotebookTrusted = hasTrustedBookPath && this.books.some(bookModel => bookModel.getNotebook(normalizedNotebookUri));
return isNotebookTrusted;
}