diff: add color-words toggle with ctrl-x keybinding#5209
Conversation
Enable users to toggle word-level diffs (git --color-words) from within the application without modifying config files. This provides a more granular view of changes for detailed code review by highlighting word-level modifications instead of full-line diffs. - add ColorWordsInDiffView config option to track state across sessions - add --color-words flag to all diff command builders (commit, diff, stash, working tree) - add Ctrl+X keybinding to toggle color-words mode - prevent toggling in staging contexts where word-level diffs are unsupported - show "(color words)" subtitle indicator when mode is active - add translations for keybinding, tooltip, subtitle, and error message Signed-off-by: Eric Wheeler <lazygit@z.ewheeler.org>
I'm sorry to hear that. It sure is cleaner to see this instead of the one below it. The first one looks amazing like magic. It shows me exactly which columns were added to the structure, but the second one is rather messy.
versus
|
|
@KJ7LNW It seems that you didn't read the discussion that I linked to. Of course your second screenshot is terrible, and that's not what I'm suggesting as an alternative. My point is that good custom pagers already do a great job at highlighting such differences out of the box; here's your diff rendered by delta, which is my preferred pager:
I admit that the rewrapped comment at the top is not as nice as in your screenshot, but the table is ok. This is the default diff display, no need to switch modes. For tricker cases where delta doesn't manage to highlight the changes well enough I tend to switch to difftastic, which is similar to If you really want to use Reasons why I don't want to add this as a builtin toggle like this PR does:
|
I did look at the other PR discussion but I misunderstood: I thought somehow you had a custom PAGER= hook related to lazygit that somehow helped you with formatting via the child's stdout, and that my pull request hack somehow would break that.
Awesome. I always prefer the clean and architecturally correct implementation. Thank you for pointing that out. |
|
After writing that comment, I realized there might not be an easy way to toggle with a hotkey. Sometimes line diffs and sometimes word diffs are more useful than the other. I just read your documentation in #5795: Does Lazygit have a mechanism for toggling pagers (ie, diff style) with a hotkey? edit: It looks like there's a hotkey for cycling pagers, so perhaps never mind. |
|
Yes, it's BTW, we recently realized that "pager" is totally the wrong term to use for these, so it's probably going to change to something like "diff renderer" in a future version. |




Description
Adds runtime toggle for word-level diffs using git's
--color-wordsflag. Complements existing whitespace toggle by providing finer-grained diff visualization.Example
The code in this example is out of context, but it shows how word-level diffing can be used to see what actually changed. This is a sample of what it looks like in lazy git when you apply the word level change and enable it:
Type of Change
Implementation Details
Mirrors whitespace toggle architecture:
git.colorWordsInDiffView(default: false)toggle_color_words_action.gowith context exclusions for staging/patch-building<c-x>registered inglobal_controller.go--color-wordsflag conditionally todiff,show, andstash showcommandsBoth flags can be enabled simultaneously in git commands without conflict.
Testing