提交 2158b1aa 编写于 作者: J Jackson Kearl

[Search Editor] Align results from the same file

上级 24a5df3c
......@@ -113,8 +113,8 @@ mappings.forEach(([ext, scope, regexp]) =>
patterns: [
{
name: [scopes.resultBlock.result.meta, scopes.resultBlock.result.metaMultiLine].join(' '),
begin: '^ ((\\d+) )',
while: '^ (?:((\\d+)(:))|((\\d+) ))',
begin: '^ (?:\\s*)((\\d+) )',
while: '^ (?:\\s*)(?:((\\d+)(:))|((\\d+) ))',
beginCaptures: {
'0': { name: scopes.resultBlock.result.prefix.meta },
'1': { name: scopes.resultBlock.result.prefix.metaContext },
......@@ -132,7 +132,7 @@ mappings.forEach(([ext, scope, regexp]) =>
patterns: [{ include: scope }]
},
{
begin: '^ ((\\d+)(:))',
begin: '^ (?:\\s*)((\\d+)(:))',
while: '(?=not)possible',
name: [scopes.resultBlock.result.meta, scopes.resultBlock.result.metaSingleLine].join(' '),
beginCaptures: {
......@@ -214,7 +214,7 @@ const plainText = [
}
},
{
match: '^ (?:((\\d+)(:))|((\\d+)( ))(.*))',
match: '^ (?:\\s*)(?:((\\d+)(:))|((\\d+)( ))(.*))',
name: [scopes.resultBlock.meta, scopes.resultBlock.result.meta].join(' '),
captures: {
'1': { name: [scopes.resultBlock.result.prefix.meta, scopes.resultBlock.result.prefix.metaMatch].join(' ') },
......
......@@ -22,11 +22,10 @@ const translateRangeLines =
(range: Range) =>
new Range(range.startLineNumber + n, range.startColumn, range.endLineNumber + n, range.endColumn);
const matchToSearchResultFormat = (match: Match): { line: string, ranges: Range[], lineNumber: string }[] => {
const matchToSearchResultFormat = (match: Match, longestLineNumber: number): { line: string, ranges: Range[], lineNumber: string }[] => {
const getLinePrefix = (i: number) => `${match.range().startLineNumber + i}`;
const fullMatchLines = match.fullPreviewLines();
const largestPrefixSize = fullMatchLines.reduce((largest, _, i) => Math.max(getLinePrefix(i).length, largest), 0);
const results: { line: string, ranges: Range[], lineNumber: string }[] = [];
......@@ -34,8 +33,8 @@ const matchToSearchResultFormat = (match: Match): { line: string, ranges: Range[
fullMatchLines
.forEach((sourceLine, i) => {
const lineNumber = getLinePrefix(i);
const paddingStr = repeat(' ', largestPrefixSize - lineNumber.length);
const prefix = ` ${lineNumber}: ${paddingStr}`;
const paddingStr = repeat(' ', longestLineNumber - lineNumber.length);
const prefix = ` ${paddingStr}${lineNumber}: `;
const prefixOffset = prefix.length;
const line = (prefix + sourceLine).replace(/\r?\n?$/, '');
......@@ -60,9 +59,9 @@ const matchToSearchResultFormat = (match: Match): { line: string, ranges: Range[
type SearchResultSerialization = { text: string[], matchRanges: Range[] };
function fileMatchToSearchResultFormat(fileMatch: FileMatch, labelFormatter: (x: URI) => string): SearchResultSerialization {
const serializedMatches = flatten(fileMatch.matches()
.sort(searchMatchComparer)
.map(match => matchToSearchResultFormat(match)));
const sortedMatches = fileMatch.matches().sort(searchMatchComparer);
const longestLineNumber = sortedMatches[sortedMatches.length - 1].range().endLineNumber.toString().length;
const serializedMatches = flatten(sortedMatches.map(match => matchToSearchResultFormat(match, longestLineNumber)));
const uriString = labelFormatter(fileMatch.resource);
let text: string[] = [`${uriString}:`];
......@@ -84,7 +83,7 @@ function fileMatchToSearchResultFormat(fileMatch: FileMatch, labelFormatter: (x:
if (lastLine !== undefined && lineNumber !== lastLine + 1) {
text.push('');
}
text.push(` ${lineNumber} ${line}`);
text.push(` ${repeat(' ', longestLineNumber - `${lineNumber}`.length)}${lineNumber} ${line}`);
lastLine = lineNumber;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册