-
Notifications
You must be signed in to change notification settings - Fork 382
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
Fix git-grep match-highlighting at line-start #1057
Conversation
])) | ||
); | ||
|
||
let broken_example = format!("foo/bar/baz.yaml{escape}[36m:{escape}[m2{escape}[36m:{escape}[m{escape}[1;31mkind: Service{escape}[m"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variable-names aren't really applicable anymore. working_example
was the one that worked before the changes were made to get_code_style_sections
, broken_example
was the one that didn't. That wouldn't actually be a useful distinction going forward; maybe we should rename them?
}, | ||
) { | ||
let match_style_sections = ansi::parse_style_sections(&raw_line[raw_code_start..]) | ||
let match_style_sections = ansi::parse_style_sections(&raw_line[(prefix_end + 1)..]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are no escape-code-sequences separating the prefix-section from the code-section, the old approach would have produced the same value as the new approach. If there are escape-code-sequences between the two, the old approach would have skipped them, which isn't what we want. So I think this is okay?
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.
9291bd9
to
875e22c
Compare
Hi @jdpopkin, I'm really sorry for being so slow here. I really appreciate you working on this bug. I did a quick manual test and I'm thinking that there might be a tiny bit more work needed here. Try On masterOn this branchSo it looks like your branch is extending the highlighting too far in some cases. Do you agree / see that also? |
Yeah, I see the same thing on my end - it looks like my branch gets the highlighting wrong for all lines where the first non-whitespace character is |
So it looks like some of the weirdness here comes from
With ANSI codes spelled out in words and some of the filename removed:
That looks normal in my standard green-on-black terminal, but not in this one: So: for some reason, We can work around that by checking for bold sections rather than non-default-foreground-color ones. I'm not really sure whether or not that's, like, a universal answer - there might be things other than pattern-matches that get formatted as bold, and maybe it'll run into trouble with users who customize git color config. If it makes sense to commit to default-git-colors-or-else, it could look for bold+red style-sections. If not, maybe the criteria used by Anyway, I added a test that repros the scenario you ran into, along with a code change that makes edit: forgot to run |
a24caca
to
85a21a9
Compare
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.
85a21a9
to
2aa2c0c
Compare
As it turns out, the files where this is happening are example-files used for testing raw git output. In this case, these lines are green because they literally contain ANSI color codes making them green. And since ANSI color codes are what delta relies on to tell where the match-boundaries are in I think checking for bold or maybe red+bold (the default format for a grep match) instead of checking for a non-default foreground color makes sense here. That would fix the existing problems covering lines in |
Thanks @jdpopkin! The code change is very clean and it seems to work so I think that's great and I've merged it. (By the way, I agree that |
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.