Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 git grep handler doesn't highlight matches that start in column 0 #1056

Closed
2 tasks done
jdpopkin opened this issue Apr 25, 2022 · 0 comments · Fixed by #1057
Closed
2 tasks done

🐛 git grep handler doesn't highlight matches that start in column 0 #1056

jdpopkin opened this issue Apr 25, 2022 · 0 comments · Fixed by #1057

Comments

@jdpopkin
Copy link
Contributor

jdpopkin commented Apr 25, 2022

Hi! It looks like the git grep handler can't highlight the grep-match if the grep-match starts at the beginning of the line of code. I'm not sure if this is always the case or if it's specific to my type of terminal in some way (I'm using Terminal.app on macOS).

To repro,

mkdir /tmp/delta-test
cd /tmp/delta-test
echo 'foo' > broken.md
echo '...foo' > working.md
git init
git add .
git commit -m 'Add files to repro bug'
git grep 'foo'

On my machine, that leaves us with one line where foo is highlighted (working.md) and another line where it is not (broken.md):

Screen Shot 2022-04-25 at 7 49 27 PM

Not a big deal for a trivial case like this (where the entire line matches the query exactly), but with a more complicated regex it can be annoying.

I have a fix for this. It's a little bit weird, but I think it should be okay.

  • Please include the raw text output from git, so that we can reproduce the problem.
    The problem is in handling of ANSI color codes, which I suspect cannot be pasted here? But here's a cat -v representation of what GIT_PAGER=less git color.grep=always grep 'foo' does here:
broken.md^[[36m:^[[m1^[[36m:^[[m^[[1;31mfoo^[[m
working.md^[[36m:^[[m1^[[36m:^[[m...^[[1;31mfoo^[[m

(Pretty hard to visually parse this, but: it highlights "foo" correctly on both lines.)

  • A screenshot of Delta's output is often helpful also.

Thanks for filing a Delta bug report!

jdpopkin added a commit to jdpopkin/delta that referenced this issue Apr 25, 2022
This commit fixes highlighting the part of the line of code that matches
the git grep query in cases where the match starts at the beginning of
the lines.

Fixes dandavison#1056.
jdpopkin added a commit to jdpopkin/delta that referenced this issue Apr 26, 2022
This commit fixes highlighting the part of the line of code that matches
the git grep query in cases where the match starts at the beginning of
the lines.

Fixes dandavison#1056.
dandavison pushed a commit that referenced this issue Jul 16, 2022
* Fix git-grep match-highlighting at line-start

This commit fixes highlighting the part of the line of code that matches
the git grep query in cases where the match starts at the beginning of
the lines.

Fixes #1056.

* Fix handling of non-match highlight

In some cases, `git grep` will customize the foreground-color for more
than just the subset of the line that matches the grep pattern. This
breaks the current match-detection behavior, which considers any
characters with a non-default "foreground color" within the "code" part
of a git-grep-ouput-line to be part of the match. This commit makes
match-detection check for boldness and a red foreground instead of just
checking for a non-default foreground-color.

git grep matches are bold and red by default. But git grep isn't the
only reason input to delta may contain color codes; there may still be
cases where the highlighting looks wrong here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant