Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to select match when clicking search editor results #136002

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,11 @@ configurationRegistry.registerConfiguration({
],
markdownDescription: nls.localize('search.searchEditor.doubleClickBehaviour', "Configure effect of double clicking a result in a search editor.")
},
'search.searchEditor.openLocationToMatch': {
type: 'boolean',
default: false,
markdownDescription: nls.localize('search.searchEditor.openLocationToMatch', "When opening a location from the search editor, set selection to first match in line.")
},
'search.searchEditor.reusePriorSearchConfiguration': {
type: 'boolean',
default: false,
Expand Down
20 changes: 17 additions & 3 deletions src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,29 @@ export class SearchEditor extends BaseTextEditor<SearchEditorViewState> {

private registerEditorListeners() {
this.searchResultEditor = super.getControl() as CodeEditorWidget;
this.searchResultEditor.onMouseUp(e => {
this.searchResultEditor.onMouseUp(async e => {
if (e.event.detail === 2) {
const behaviour = this.searchConfig.searchEditor.doubleClickBehaviour;
const position = e.target.position;
if (position && behaviour !== 'selectWord') {
const line = this.searchResultEditor.getModel()?.getLineContent(position.lineNumber) ?? '';
if (line.match(RESULT_LINE_REGEX)) {
const lineMatch = line.match(RESULT_LINE_REGEX);
if (lineMatch) {
this.searchResultEditor.setSelection(Range.fromPositions(position));
this.commandService.executeCommand(behaviour === 'goToLocation' ? 'editor.action.goToDeclaration' : 'editor.action.openDeclarationToTheSide');
const cmd = this.commandService.executeCommand(behaviour === 'goToLocation' ? 'editor.action.goToDeclaration' : 'editor.action.openDeclarationToTheSide');
// Check if we should select the first match.
if (this.searchConfig.searchEditor.openLocationToMatch) {
const searchMatchDecoration = this.searchResultEditor.getModel()?.getLineDecorations(position.lineNumber).find(ld => ld.options.description === 'search-editor-find-match');
if (searchMatchDecoration) {
const matchRange = searchMatchDecoration.range;
const offset = lineMatch[1].length + lineMatch[2].length + lineMatch[3].length;
const matchLine = parseInt(lineMatch[2], 10);
const selectionRange = new Range(matchLine, matchRange.startColumn - offset, matchLine, matchRange.endColumn - offset);
// Wait for the editor to open, then set selection.
await cmd;
this.editorService.activeTextEditorControl?.setSelection(selectionRange);
}
}
} else if (line.match(FILE_LINE_REGEX)) {
this.searchResultEditor.setSelection(Range.fromPositions(position));
this.commandService.executeCommand('editor.action.peekDefinition');
Expand Down
9 changes: 5 additions & 4 deletions src/vs/workbench/services/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,11 @@ export interface ISearchConfigurationProperties {
searchOnTypeDebouncePeriod: number;
mode: 'view' | 'reuseEditor' | 'newEditor';
searchEditor: {
doubleClickBehaviour: 'selectWord' | 'goToLocation' | 'openLocationToSide';
reusePriorSearchConfiguration: boolean;
defaultNumberOfContextLines: number | null;
experimental: {};
doubleClickBehaviour: 'selectWord' | 'goToLocation' | 'openLocationToSide',
reusePriorSearchConfiguration: boolean,
openLocationToMatch: boolean,
defaultNumberOfContextLines: number | null,
experimental: {}
};
sortOrder: SearchSortOrder;
}
Expand Down