From 6f2fe8a791646d6d662e89d7eccf6c515ccc9c8c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 27 Sep 2024 15:14:39 +0800 Subject: vim-patch:9.1.0743: diff mode does not handle overlapping diffs correctly (#30532) Problem: diff mode does not handle overlapping diffs correctly Solution: correct the logic to handle overlapping blocks (Yukihiro Nakadaira) Vim merges overlapped diff blocks and it doesn't work expectedly in some situation. closes: vim/vim#15735 https://github.com/vim/vim/commit/06fe70c183a53ea97cd42ace490d4fb9fd14f042 Co-authored-by: Yukihiro Nakadaira --- src/nvim/diff.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 0c59b8eb67..05e5bed50c 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1609,6 +1609,7 @@ static void process_hunk(diff_T **dpp, diff_T **dprevp, int idx_orig, int idx_ne for (int i = idx_orig; i < idx_new; i++) { if (curtab->tp_diffbuf[i] != NULL) { dp->df_lnum[i] -= off; + dp->df_count[i] += off; } } dp->df_lnum[idx_new] = hunk->lnum_new; @@ -1619,11 +1620,7 @@ static void process_hunk(diff_T **dpp, diff_T **dprevp, int idx_orig, int idx_ne dp->df_count[idx_new] = (linenr_T)hunk->count_new - off; } else { // second overlap of new block with existing block - dp->df_count[idx_new] += (linenr_T)hunk->count_new - (linenr_T)hunk->count_orig - + dpl->df_lnum[idx_orig] + - dpl->df_count[idx_orig] - - (dp->df_lnum[idx_orig] + - dp->df_count[idx_orig]); + dp->df_count[idx_new] += (linenr_T)hunk->count_new; } // Adjust the size of the block to include all the lines to the @@ -1632,11 +1629,8 @@ static void process_hunk(diff_T **dpp, diff_T **dprevp, int idx_orig, int idx_ne - (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]); if (off < 0) { - // new change ends in existing block, adjust the end if not - // done already - if (*notsetp) { - dp->df_count[idx_new] += -off; - } + // new change ends in existing block, adjust the end + dp->df_count[idx_new] += -off; off = 0; } -- cgit