aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/diff.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-02-03 21:52:53 +0800
committerzeertzjq <zeertzjq@outlook.com>2025-02-04 08:42:53 +0800
commit290bb4c64bdcc475c29b857dc8626f5c51aa2b8d (patch)
treeaf9c68ab653a2cc24dc3d6b6993e0133f9590c50 /src/nvim/diff.c
parent5a7cf85c2c7e452563a4bce9195e9a3426ca3050 (diff)
downloadrneovim-290bb4c64bdcc475c29b857dc8626f5c51aa2b8d.tar.gz
rneovim-290bb4c64bdcc475c29b857dc8626f5c51aa2b8d.tar.bz2
rneovim-290bb4c64bdcc475c29b857dc8626f5c51aa2b8d.zip
vim-patch:9.1.1009: diff feature can be improved
Problem: diff feature can be improved Solution: include the linematch diff alignment algorithm (Jonathon) closes: vim/vim#9661 https://github.com/vim/vim/commit/7c7a4e6d1ad50d5b25b42aa2d5a33a8d04a4cc8a Co-authored-by: Jonathon <jonathonwhite@protonmail.com>
Diffstat (limited to 'src/nvim/diff.c')
-rw-r--r--src/nvim/diff.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 99f70793b3..4ead58c74f 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -1820,7 +1820,8 @@ static void find_top_diff_block(diff_T **thistopdiff, diff_T **nextblockblock, i
topdiffchange = 0;
}
- // check if the fromwin topline is matched by the current diff. if so, set it to the top of the diff block
+ // check if the fromwin topline is matched by the current diff. if so,
+ // set it to the top of the diff block
if (topline >= topdiff->df_lnum[fromidx] && topline <=
(topdiff->df_lnum[fromidx] + topdiff->df_count[fromidx])) {
// this line is inside the current diff block, so we will save the
@@ -2021,10 +2022,15 @@ static void run_linematch_algorithm(diff_T *dp)
size_t ndiffs = 0;
for (int i = 0; i < DB_COUNT; i++) {
if (curtab->tp_diffbuf[i] != NULL) {
- // write the contents of the entire buffer to
- // diffbufs_mm[diffbuffers_count]
- diff_write_buffer(curtab->tp_diffbuf[i], &diffbufs_mm[ndiffs],
- dp->df_lnum[i], dp->df_lnum[i] + dp->df_count[i] - 1);
+ if (dp->df_count[i] > 0) {
+ // write the contents of the entire buffer to
+ // diffbufs_mm[diffbuffers_count]
+ diff_write_buffer(curtab->tp_diffbuf[i], &diffbufs_mm[ndiffs],
+ dp->df_lnum[i], dp->df_lnum[i] + dp->df_count[i] - 1);
+ } else {
+ diffbufs_mm[ndiffs].size = 0;
+ diffbufs_mm[ndiffs].ptr = NULL;
+ }
diffbufs[ndiffs] = &diffbufs_mm[ndiffs];
@@ -2060,6 +2066,12 @@ static void run_linematch_algorithm(diff_T *dp)
/// Returns > 0 for inserting that many filler lines above it (never happens
/// when 'diffopt' doesn't contain "filler").
/// This should only be used for windows where 'diff' is set.
+/// When diffopt contains linematch, a changed/added/deleted line
+/// may also have filler lines above it. In such a case, the possibilities
+/// are no longer mutually exclusive. The number of filler lines is
+/// returned from diff_check, and the integer 'linestatus' passed by
+/// pointer is set to -1 to indicate a changed line, and -2 to indicate an
+/// added line
///
/// @param wp
/// @param lnum