Skip to content

Commit b9dd2ef

Browse files
author
Jackson Kearl
committed
Allow searching from selection inside search editor
1 parent 68b2a66 commit b9dd2ef

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/vs/workbench/contrib/search/browser/searchEditor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,14 @@ export class SearchEditor extends BaseEditor {
336336
this.queryEditorWidget.focus();
337337
}
338338

339+
getSelected() {
340+
const selection = this.searchResultEditor.getSelection();
341+
if (selection) {
342+
return this.searchResultEditor.getModel()?.getValueInRange(selection) ?? '';
343+
}
344+
return '';
345+
}
346+
339347
private reLayout() {
340348
if (this.dimension) {
341349
this.queryEditorWidget.setWidth(this.dimension.width - 28 /* container margin */);

src/vs/workbench/contrib/search/browser/searchEditorActions.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,33 @@ import { ILabelService } from 'vs/platform/label/common/label';
1313
import { SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
1414
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1515
import { SearchEditor } from 'vs/workbench/contrib/search/browser/searchEditor';
16-
import { getOrMakeSearchEditorInput } from 'vs/workbench/contrib/search/browser/searchEditorInput';
16+
import { getOrMakeSearchEditorInput, SearchEditorInput } from 'vs/workbench/contrib/search/browser/searchEditorInput';
1717
import { serializeSearchResultForEditor, serializeSearchConfiguration } from 'vs/workbench/contrib/search/browser/searchEditorSerialization';
1818

19+
1920
export const openNewSearchEditor =
2021
async (editorService: IEditorService, instantiationService: IInstantiationService) => {
2122
const activeEditor = editorService.activeTextEditorWidget;
2223
let activeModel: ICodeEditor | undefined;
23-
if (isDiffEditor(activeEditor)) {
24-
if (activeEditor.getOriginalEditor().hasTextFocus()) {
25-
activeModel = activeEditor.getOriginalEditor();
24+
let selected = '';
25+
if (activeEditor) {
26+
if (isDiffEditor(activeEditor)) {
27+
if (activeEditor.getOriginalEditor().hasTextFocus()) {
28+
activeModel = activeEditor.getOriginalEditor();
29+
} else {
30+
activeModel = activeEditor.getModifiedEditor();
31+
}
2632
} else {
27-
activeModel = activeEditor.getModifiedEditor();
33+
activeModel = activeEditor as ICodeEditor;
2834
}
35+
const selection = activeModel?.getSelection();
36+
selected = (selection && activeModel?.getModel()?.getValueInRange(selection)) ?? '';
2937
} else {
30-
activeModel = activeEditor as ICodeEditor | undefined;
38+
if (editorService.activeEditor instanceof SearchEditorInput) {
39+
const active = editorService.activeControl as SearchEditor;
40+
selected = active.getSelected();
41+
}
3142
}
32-
const selection = activeModel?.getSelection();
33-
let selected = (selection && activeModel?.getModel()?.getValueInRange(selection)) ?? '';
34-
3543

3644
const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { text: serializeSearchConfiguration({ query: selected }) });
3745
await editorService.openEditor(input, { pinned: true });

0 commit comments

Comments
 (0)