Skip to content
Merged
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
18 changes: 11 additions & 7 deletions src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ export class RipgrepParser extends EventEmitter {

private createTextSearchMatch(data: IRgMatch, uri: vscode.Uri): vscode.TextSearchMatch {
const lineNumber = data.line_number - 1;
const fullText = bytesOrTextToString(data.lines);
let isBOMStripped = false;
let fullText = bytesOrTextToString(data.lines);
if (lineNumber === 0 && startsWithUTF8BOM(fullText)) {
isBOMStripped = true;
fullText = stripUTF8BOM(fullText);
}
const fullTextBytes = Buffer.from(fullText);

let prevMatchEnd = 0;
Expand All @@ -255,6 +260,11 @@ export class RipgrepParser extends EventEmitter {
}

let matchText = bytesOrTextToString(match.match);
if (lineNumber === 0 && i === 0 && isBOMStripped) {
matchText = stripUTF8BOM(matchText);
match.start = match.start <= 3 ? 0 : match.start - 3;
match.end = match.end <= 3 ? 0 : match.end - 3;
}
const inBetweenChars = fullTextBytes.slice(prevMatchEnd, match.start).toString().length;
let startCol = prevMatchEndCol + inBetweenChars;

Expand All @@ -265,12 +275,6 @@ export class RipgrepParser extends EventEmitter {
stats.lastLineLength :
stats.lastLineLength + startCol;

if (lineNumber === 0 && i === 0 && startsWithUTF8BOM(matchText)) {
matchText = stripUTF8BOM(matchText);
startCol -= 3;
endCol -= 3;
}

prevMatchEnd = match.end;
prevMatchEndCol = endCol;
prevMatchEndLine = endLineNumber;
Expand Down