From 415689de9f6492a94c54da00e8198e490adb5c99 Mon Sep 17 00:00:00 2001 From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com> Date: Fri, 12 Feb 2021 16:51:14 -0800 Subject: [PATCH] Fix search results display (#14265) * fix search results * fix paths for windows --- .../notebookExplorerViewlet.ts | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookExplorerViewlet.ts b/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookExplorerViewlet.ts index 3627ebd7cc..175490a519 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookExplorerViewlet.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookExplorerViewlet.ts @@ -38,7 +38,6 @@ import { getOutOfWorkspaceEditorResources } from 'vs/workbench/contrib/search/co import { NotebookSearchView } from 'sql/workbench/contrib/notebook/browser/notebookExplorer/notebookSearch'; import * as path from 'vs/base/common/path'; import { URI } from 'vs/base/common/uri'; -import { isString } from 'vs/base/common/types'; import { TreeViewPane } from 'vs/workbench/browser/parts/views/treeView'; export const VIEWLET_ID = 'workbench.view.notebooks'; @@ -260,7 +259,11 @@ export class NotebookExplorerViewPaneContainer extends ViewPaneContainer { this.validateQuery(query).then(() => { if (this.views.length > 1) { let filesToIncludeFiltered: string = ''; - this.views.forEach(async (v) => { + // search book results first and then notebooks + const pinnedNotebookIndex = this.views.findIndex(view => view.id === 'pinnedBooksView'); + const viewPanes = this.views; + viewPanes.push(viewPanes.splice(pinnedNotebookIndex, 1)[0]); + viewPanes.forEach(async (v) => { if (v instanceof TreeViewPane) { const { treeView } = (Registry.as(ViewContainerExtensions.ViewsRegistry).getView(v.id)); if (treeView.dataProvider) { @@ -268,32 +271,34 @@ export class NotebookExplorerViewPaneContainer extends ViewPaneContainer { items?.forEach(root => { this.updateViewletsState(); if (root.contextValue === 'providedBook' || root.contextValue === 'savedBook') { - let rootFolder = URI.file(root.resourceUri.path); + const rootFolder = URI.file(root.resourceUri.path); let folderToSearch = { folder: rootFolder }; if (root.tooltip.toString().includes('content')) { let pattern = {}; pattern['content/**'] = true; folderToSearch['includePattern'] = pattern; } - query.folderQueries = query.folderQueries.filter((folder) => { - if (!!folder.includePattern && !folder.includePattern.toString().startsWith('content')) { - //verify if pinned notebook is not opened in Books Viewlet - return path.relative(folder.folder.fsPath, folderToSearch.folder.fsPath) !== '..'; - } else { - return true; - } - }); query.folderQueries.push(folderToSearch); filesToIncludeFiltered = filesToIncludeFiltered + path.join(folderToSearch.folder.fsPath, '**', '*.md') + ',' + path.join(folderToSearch.folder.fsPath, '**', '*.ipynb') + ','; } else { let pattern = {}; - let rootFolder = URI.file(path.dirname(root.resourceUri.path)); - let pathToNotebook = isString(root.tooltip) ? root.tooltip : root.tooltip.value; - let baseName = path.join('**', path.basename(pathToNotebook)); + const rootFolder = URI.file(path.dirname(root.resourceUri.path)); + const baseName = path.join('**', path.basename(root.resourceUri.path)).replace(/\\/g, '/'); + let isOpenedInBooksView = false; pattern[baseName] = true; - let folderToSearch = { folder: rootFolder, includePattern: pattern }; - query.folderQueries.push(folderToSearch); - filesToIncludeFiltered = filesToIncludeFiltered + rootFolder + ','; + query.folderQueries.forEach((folder) => { + //check for books + if ((folder.includePattern === undefined || folder.includePattern['content/**']) && !isOpenedInBooksView) { + //verify if pinned notebook is not opened in Books Viewlet + const relativePath = path.relative(folder.folder.fsPath, rootFolder.fsPath); + isOpenedInBooksView = !relativePath.startsWith('..') || !relativePath.startsWith('.'); + } + }); + if (!isOpenedInBooksView) { + const folderToSearch = { folder: rootFolder, includePattern: pattern }; + query.folderQueries.push(folderToSearch); + filesToIncludeFiltered = filesToIncludeFiltered + rootFolder + ','; + } } });