Fix: matches in context lines do not get highlighted
Created by: attfarhan
Fixes https://github.com/sourcegraph/sourcegraph/issues/6900.
This was a little trickier to fix than I thought.
The reason these lines weren't getting highlighted was that they were context lines, so the matches on these lines were filtered out in FileMatchChildren
, while we only decide to render the context lines in CodeExcerpt
.
Why did we decide to filter out the match in the context lines? Something unknown to the user, is that we limit the number of matches to display in the preview to 10 matches (in a single file). Everything else is viewable and highlighted by clicking "Show x more matches".
In the bugs listed in the issue, those matches we expected to be highlighted were match number 11 in their respective files. Therefore, in FileMatchChildren
, they were filtered out. In CodeExcerpt
, when we decide which part of the blob to display, we include the contextLine. Now, if there's a match highlight that appears the context lines, it will be highlighted.
However, we don't want to add more context lines if there is now a highlight in one of the context lines. The caveat here is that our users do not know that there's a 10-match limit in the result previews. Therefore, if there are already 10 matches in a result preview, and the 11th appears on a context line, it will look as if we are not providing the correct number of context lines, which may seem like a bug to attentive users. I think this is a reasonable tradeoff. It's less misleading, and is ultimately more "correct" behavior.