show find in notebook when opening from searchResults view (#14447)

* initial changes

* open notebook through our command

* address comments
This commit is contained in:
Maddy
2021-03-05 10:49:09 -08:00
committed by GitHub
parent f6f45bc3f9
commit b82942a030
4 changed files with 40 additions and 3 deletions

View File

@@ -321,6 +321,10 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
this._findInput.focus(); this._findInput.focus();
} }
public setFindInput(searchTerm: string): void {
this._findInput.inputBox.value = searchTerm;
}
public highlightFindOptions(): void { public highlightFindOptions(): void {
this._findInput.highlightFindOptions(); this._findInput.highlightFindOptions();
} }

View File

@@ -5,7 +5,7 @@
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor'; import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; 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 { localize } from 'vs/nls';
import { IEditorInputFactoryRegistry, Extensions as EditorInputFactoryExtensions, ActiveEditorContext } from 'vs/workbench/common/editor'; 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 { isMacintosh } from 'vs/base/common/platform';
import { SearchSortOrder } from 'vs/workbench/services/search/common/search'; import { SearchSortOrder } from 'vs/workbench/services/search/common/search';
import { ImageMimeTypes } from 'sql/workbench/services/notebook/common/contracts'; import { ImageMimeTypes } from 'sql/workbench/services/notebook/common/contracts';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
Registry.as<IEditorInputFactoryRegistry>(EditorInputFactoryExtensions.EditorInputFactories) Registry.as<IEditorInputFactoryRegistry>(EditorInputFactoryExtensions.EditorInputFactories)
.registerEditorInputFactory(FileNotebookInput.ID, FileNoteBookEditorInputFactory); .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, { MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: { command: {

View File

@@ -399,6 +399,23 @@ export class NotebookEditor extends EditorPane implements IFindNotebookControlle
} }
} }
public async launchFind(searchTerm: string): Promise<void> {
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<void> { public async findNext(): Promise<void> {
try { try {
const p = await this.notebookFindModel.findNext(); const p = await this.notebookFindModel.findNext();

View File

@@ -229,10 +229,11 @@ export class NotebookSearchView extends SearchView {
let element = this.tree.getSelection()[0] as Match; let element = this.tree.getSelection()[0] as Match;
const resource = element instanceof Match ? element.parent().resource : (<FileMatch>element).resource; const resource = element instanceof Match ? element.parent().resource : (<FileMatch>element).resource;
if (resource.fsPath.endsWith('.md')) { if (resource.fsPath.endsWith('.md')) {
this.commandService.executeCommand('markdown.showPreview', resource); await this.commandService.executeCommand('markdown.showPreview', resource);
} else { } 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);
} }
})); }));
} }