Skip to content

Commit dbea36b

Browse files
ssigwartJackson Kearl
andauthored
Search editor go to location improvements (microsoft#135227)
* Search editor go to location improvements - Added option to go to and select the match - Fixed cursor placement with initial whitespace * Remove microsoft#128927 changes * Fix up seprartor logic Co-authored-by: Jackson Kearl <[email protected]>
1 parent f6a5fbe commit dbea36b

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

extensions/search-result/src/extension.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77
import * as pathUtils from 'path';
88

99
const FILE_LINE_REGEX = /^(\S.*):$/;
10-
const RESULT_LINE_REGEX = /^(\s+)(\d+)(:| )(\s+)(.*)$/;
10+
const RESULT_LINE_REGEX = /^(\s+)(\d+)(: | )(\s*)(.*)$/;
1111
const ELISION_REGEX = / ([0-9]+) characters skipped /g;
1212
const SEARCH_RESULT_SELECTOR = { language: 'search-result', exclusive: true };
1313
const DIRECTIVES = ['# Query:', '# Flags:', '# Including:', '# Excluding:', '# ContextLines:'];
@@ -220,10 +220,9 @@ function parseSearchResults(document: vscode.TextDocument, token?: vscode.Cancel
220220

221221
const resultLine = RESULT_LINE_REGEX.exec(line);
222222
if (resultLine) {
223-
const [, indentation, _lineNumber, seperator, resultIndentation] = resultLine;
223+
const [, indentation, _lineNumber, separator] = resultLine;
224224
const lineNumber = +_lineNumber - 1;
225-
const resultStart = (indentation + _lineNumber + seperator + resultIndentation).length;
226-
const metadataOffset = (indentation + _lineNumber + seperator).length;
225+
const metadataOffset = (indentation + _lineNumber + separator).length;
227226
const targetRange = new vscode.Range(Math.max(lineNumber - 3, 0), 0, lineNumber + 3, line.length);
228227

229228
let locations: Required<vscode.LocationLink>[] = [];
@@ -233,12 +232,12 @@ function parseSearchResults(document: vscode.TextDocument, token?: vscode.Cancel
233232
targetRange,
234233
targetSelectionRange: new vscode.Range(lineNumber, 0, lineNumber, 1),
235234
targetUri: currentTarget,
236-
originSelectionRange: new vscode.Range(i, 0, i, resultStart),
235+
originSelectionRange: new vscode.Range(i, 0, i, metadataOffset - 1),
237236
});
238237

239-
let lastEnd = resultStart;
238+
let lastEnd = metadataOffset;
240239
let offset = 0;
241-
ELISION_REGEX.lastIndex = resultStart;
240+
ELISION_REGEX.lastIndex = metadataOffset;
242241
for (let match: RegExpExecArray | null; (match = ELISION_REGEX.exec(line));) {
243242
locations.push({
244243
targetRange,
@@ -261,7 +260,7 @@ function parseSearchResults(document: vscode.TextDocument, token?: vscode.Cancel
261260
}
262261

263262
currentTargetLocations?.push(...locations);
264-
links[i] = { type: 'result', locations, isContext: seperator === ' ', prefixRange: new vscode.Range(i, 0, i, metadataOffset) };
263+
links[i] = { type: 'result', locations, isContext: separator === ' ', prefixRange: new vscode.Range(i, 0, i, metadataOffset) };
265264
}
266265
}
267266

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { renderSearchMessage } from 'vs/workbench/contrib/search/browser/searchM
6262
import { EditorExtensionsRegistry, IEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
6363
import { UnusualLineTerminatorsDetector } from 'vs/editor/contrib/unusualLineTerminators/unusualLineTerminators';
6464

65-
const RESULT_LINE_REGEX = /^(\s+)(\d+)(:| )(\s+)(.*)$/;
65+
const RESULT_LINE_REGEX = /^(\s+)(\d+)(: | )(\s*)(.*)$/;
6666
const FILE_LINE_REGEX = /^(\S.*):$/;
6767

6868
type SearchEditorViewState = ICodeEditorViewState & { focused: 'input' | 'editor' };

0 commit comments

Comments
 (0)