Skip to content

Commit

Permalink
fix(search): match highlighting for multiple matches
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Jun 3, 2020
1 parent 6127b01 commit a16e5a7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions PSSourcegraph/Formats/Search.Format.ps1xml
Expand Up @@ -116,16 +116,22 @@
$start = 0
foreach ($offsetAndLength in $_.OffsetAndLengths) {
$offset, $length = $offsetAndLength
$out += $preview.Substring($start, $offset - $start) + "`e[43m`e[30m" + $preview.Substring($offset, $length) + "`e[0m"
$start += $offset + $length
$out +=
# Not highlighted
$preview.Substring($start, $offset - $start) +
"`e[43m`e[30m" +
# Highlighted
$preview.Substring($offset, $length) +
"`e[0m"
$start = $offset + $length
}
# Add rest
if ($preview.Length -gt $start) {
$out += $preview.Substring($start)
}
$out
} catch {
Write-Warning -Message ("Error highlighting matches: " + ($_ | Out-String))
Write-Warning -Message "Error highlighting matches: $($_ | Out-String)`nPreview: $($result.Preview | ConvertTo-Json)`nOffsetAndLengths: $($result.OffsetAndLengths | ConvertTo-Json -Compress)"
$result.Preview
}
</ScriptBlock>
Expand Down

0 comments on commit a16e5a7

Please sign in to comment.