From b82942a030da2818af5d9cd7dbd8c7c6117bf4f8 Mon Sep 17 00:00:00 2001 From: Maddy <12754347+MaddyDev@users.noreply.github.com> Date: Fri, 5 Mar 2021 10:49:09 -0800 Subject: [PATCH] show find in notebook when opening from searchResults view (#14447) * initial changes * open notebook through our command * address comments --- .../notebook/browser/find/notebookFindWidget.ts | 4 ++++ .../notebook/browser/notebook.contribution.ts | 17 ++++++++++++++++- .../contrib/notebook/browser/notebookEditor.ts | 17 +++++++++++++++++ .../browser/notebookExplorer/notebookSearch.ts | 5 +++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/find/notebookFindWidget.ts b/src/sql/workbench/contrib/notebook/browser/find/notebookFindWidget.ts index 50f609c4f8..884afbfd5a 100644 --- a/src/sql/workbench/contrib/notebook/browser/find/notebookFindWidget.ts +++ b/src/sql/workbench/contrib/notebook/browser/find/notebookFindWidget.ts @@ -321,6 +321,10 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL this._findInput.focus(); } + public setFindInput(searchTerm: string): void { + this._findInput.inputBox.value = searchTerm; + } + public highlightFindOptions(): void { this._findInput.highlightFindOptions(); } diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts index 013a8a6a79..9ae4af77c0 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -5,7 +5,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { localize } from 'vs/nls'; import { IEditorInputFactoryRegistry, Extensions as EditorInputFactoryExtensions, ActiveEditorContext } from 'vs/workbench/common/editor'; @@ -51,6 +51,7 @@ import 'vs/css!./media/notebook.contribution'; import { isMacintosh } from 'vs/base/common/platform'; import { SearchSortOrder } from 'vs/workbench/services/search/common/search'; import { ImageMimeTypes } from 'sql/workbench/services/notebook/common/contracts'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; Registry.as(EditorInputFactoryExtensions.EditorInputFactories) .registerEditorInputFactory(FileNotebookInput.ID, FileNoteBookEditorInputFactory); @@ -151,6 +152,20 @@ CommandsRegistry.registerCommand({ } }); +const LAUNCH_FIND_IN_NOTEBOOK = 'notebook.action.launchFindInNotebook'; + +CommandsRegistry.registerCommand({ + id: LAUNCH_FIND_IN_NOTEBOOK, + handler: async (accessor: ServicesAccessor, searchTerm: string) => { + const notebookEditor = accessor.get(IEditorService).activeEditorPane; + if (notebookEditor instanceof NotebookEditor) { + if (notebookEditor) { + await notebookEditor.setNotebookModel(); + await notebookEditor.launchFind(searchTerm); + } + } + } +}); MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { diff --git a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts index 44d6d9cd89..ecce0db4de 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts @@ -399,6 +399,23 @@ export class NotebookEditor extends EditorPane implements IFindNotebookControlle } } + public async launchFind(searchTerm: string): Promise { + this._findState.change({ + isRevealed: true, + searchString: searchTerm + }, false); + if (!this._notebookModel) { + await this.setNotebookModel(); + } + if (this._notebookModel) { + this._finder.setFindInput(searchTerm); + this._findState.change({ + searchString: searchTerm + }, false); + this._triggerInputChange(); + } + } + public async findNext(): Promise { try { const p = await this.notebookFindModel.findNext(); diff --git a/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookSearch.ts b/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookSearch.ts index 4678c76240..64baa9a14e 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookSearch.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebookExplorer/notebookSearch.ts @@ -229,10 +229,11 @@ export class NotebookSearchView extends SearchView { let element = this.tree.getSelection()[0] as Match; const resource = element instanceof Match ? element.parent().resource : (element).resource; if (resource.fsPath.endsWith('.md')) { - this.commandService.executeCommand('markdown.showPreview', resource); + await this.commandService.executeCommand('markdown.showPreview', resource); } else { - await this.open(this.tree.getSelection()[0] as Match, true, false, false); + await this.commandService.executeCommand('bookTreeView.openNotebook', resource.fsPath); } + await this.commandService.executeCommand('notebook.action.launchFindInNotebook', this.viewModel.searchResult.query?.contentPattern?.pattern); } })); }