Skip to content

Commit a16e5a7

Browse files
committed
fix(search): match highlighting for multiple matches
1 parent 6127b01 commit a16e5a7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

PSSourcegraph/Formats/Search.Format.ps1xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,22 @@
116116
$start = 0
117117
foreach ($offsetAndLength in $_.OffsetAndLengths) {
118118
$offset, $length = $offsetAndLength
119-
$out += $preview.Substring($start, $offset - $start) + "`e[43m`e[30m" + $preview.Substring($offset, $length) + "`e[0m"
120-
$start += $offset + $length
119+
$out +=
120+
# Not highlighted
121+
$preview.Substring($start, $offset - $start) +
122+
"`e[43m`e[30m" +
123+
# Highlighted
124+
$preview.Substring($offset, $length) +
125+
"`e[0m"
126+
$start = $offset + $length
121127
}
122128
# Add rest
123129
if ($preview.Length -gt $start) {
124130
$out += $preview.Substring($start)
125131
}
126132
$out
127133
} catch {
128-
Write-Warning -Message ("Error highlighting matches: " + ($_ | Out-String))
134+
Write-Warning -Message "Error highlighting matches: $($_ | Out-String)`nPreview: $($result.Preview | ConvertTo-Json)`nOffsetAndLengths: $($result.OffsetAndLengths | ConvertTo-Json -Compress)"
129135
$result.Preview
130136
}
131137
</ScriptBlock>

0 commit comments

Comments
 (0)