airblade / vim-gitgutter

A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
MIT License
8.35k stars 296 forks source link

Highligthing of previewed hunks lost “diff” background #737

Closed hadronized closed 4 years ago

hadronized commented 4 years ago

What is the latest commit SHA in your installed vim-gitgutter? ea79bc01c2efc84cf8e71fbe5fd8adbf4242739d

What vim/nvim version are you on?


NVIM v0.5.0-706-g42d13b90f
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/phaazon/aur/neovim-git/src/build/config -I/home/phaazon/aur/neovim-git/src/neovim-git/src -I/usr/include -I/home/phaazon/aur/neovim-git/src/build/src/nvim/auto -I/home/phaazon/aur/neovim-git/src/build/include
Compiled by phaazon@orchid

Features: +acl +iconv +tui



See this picture for an example:
![img_092420_203008](https://user-images.githubusercontent.com/506592/94185049-1d214500-fea5-11ea-9eae-716f719078bc.png)
hadronized commented 4 years ago

Looks like it does that if I remove and modify a line. With modify only:

img_092420_203829

airblade commented 4 years ago

The algorithm for calculating intra-line highlights requires there to be the same number of lines added as removed (a modification is treated as one line added and one line removed).

airblade commented 4 years ago

To elaborate on this, the algorithm for intra-line highlights assumes that we are just dealing with modifications – we are not adding entirely new lines or deleting lines.

Therefore in a diff, which always lists the lines removed and then the lines added, the algorithm assumes each removed line is the "same" line as the corresponding added line. To calculate intra-line highlights, the algorithm compares the first removed line to the first added line; then the second removed line to the second added line; and so on.

Therefore if the number of removed lines is not the same as the number of added lines, we are not dealing with modifications only, so don't try to add intra-line highlights at all.

There are obviously edge cases, e.g. you modify a line and also add/remove an adjacent line. In which case, ideally, the modified line would have the intra-line highlights and the added/removed adjacent line would have the normal all green or all red colour. But dealing with these edge cases is too complex – most of the time things work very well ignoring them.

hadronized commented 4 years ago

Copy that, thanks for the explanations. :)