Skip to content

Commit

Permalink
Search editor go to location improvements (#135227)
Browse files Browse the repository at this point in the history
* Search editor go to location improvements

- Added option to go to and select the match
- Fixed cursor placement with initial whitespace

* Remove #128927 changes

* Fix up seprartor logic

Co-authored-by: Jackson Kearl <jakearl@microsoft.com>
  • Loading branch information
ssigwart and Jackson Kearl committed Oct 26, 2021
1 parent f6a5fbe commit dbea36b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions extensions/search-result/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import * as pathUtils from 'path';

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

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

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

let lastEnd = resultStart;
let lastEnd = metadataOffset;
let offset = 0;
ELISION_REGEX.lastIndex = resultStart;
ELISION_REGEX.lastIndex = metadataOffset;
for (let match: RegExpExecArray | null; (match = ELISION_REGEX.exec(line));) {
locations.push({
targetRange,
Expand All @@ -261,7 +260,7 @@ function parseSearchResults(document: vscode.TextDocument, token?: vscode.Cancel
}

currentTargetLocations?.push(...locations);
links[i] = { type: 'result', locations, isContext: seperator === ' ', prefixRange: new vscode.Range(i, 0, i, metadataOffset) };
links[i] = { type: 'result', locations, isContext: separator === ' ', prefixRange: new vscode.Range(i, 0, i, metadataOffset) };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { renderSearchMessage } from 'vs/workbench/contrib/search/browser/searchM
import { EditorExtensionsRegistry, IEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
import { UnusualLineTerminatorsDetector } from 'vs/editor/contrib/unusualLineTerminators/unusualLineTerminators';

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

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

0 comments on commit dbea36b

Please sign in to comment.