Allow searching from selection inside search editor

This commit is contained in:
Jackson Kearl 2020-01-22 23:11:52 -08:00
parent 68b2a6659d
commit b9dd2ef4c3
2 changed files with 25 additions and 9 deletions

View file

@ -336,6 +336,14 @@ export class SearchEditor extends BaseEditor {
this.queryEditorWidget.focus();
}
getSelected() {
const selection = this.searchResultEditor.getSelection();
if (selection) {
return this.searchResultEditor.getModel()?.getValueInRange(selection) ?? '';
}
return '';
}
private reLayout() {
if (this.dimension) {
this.queryEditorWidget.setWidth(this.dimension.width - 28 /* container margin */);

View file

@ -13,25 +13,33 @@ import { ILabelService } from 'vs/platform/label/common/label';
import { SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { SearchEditor } from 'vs/workbench/contrib/search/browser/searchEditor';
import { getOrMakeSearchEditorInput } from 'vs/workbench/contrib/search/browser/searchEditorInput';
import { getOrMakeSearchEditorInput, SearchEditorInput } from 'vs/workbench/contrib/search/browser/searchEditorInput';
import { serializeSearchResultForEditor, serializeSearchConfiguration } from 'vs/workbench/contrib/search/browser/searchEditorSerialization';
export const openNewSearchEditor =
async (editorService: IEditorService, instantiationService: IInstantiationService) => {
const activeEditor = editorService.activeTextEditorWidget;
let activeModel: ICodeEditor | undefined;
if (isDiffEditor(activeEditor)) {
if (activeEditor.getOriginalEditor().hasTextFocus()) {
activeModel = activeEditor.getOriginalEditor();
let selected = '';
if (activeEditor) {
if (isDiffEditor(activeEditor)) {
if (activeEditor.getOriginalEditor().hasTextFocus()) {
activeModel = activeEditor.getOriginalEditor();
} else {
activeModel = activeEditor.getModifiedEditor();
}
} else {
activeModel = activeEditor.getModifiedEditor();
activeModel = activeEditor as ICodeEditor;
}
const selection = activeModel?.getSelection();
selected = (selection && activeModel?.getModel()?.getValueInRange(selection)) ?? '';
} else {
activeModel = activeEditor as ICodeEditor | undefined;
if (editorService.activeEditor instanceof SearchEditorInput) {
const active = editorService.activeControl as SearchEditor;
selected = active.getSelected();
}
}
const selection = activeModel?.getSelection();
let selected = (selection && activeModel?.getModel()?.getValueInRange(selection)) ?? '';
const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { text: serializeSearchConfiguration({ query: selected }) });
await editorService.openEditor(input, { pinned: true });