Skip to content

Commit f58a847

Browse files
committed
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Problem: Diff mode is displayed wrong when adding a line at the end of a buffer. Solution: Adjust marks in diff mode. (James McCoy, closes #1329)
1 parent 2c7292d commit f58a847

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/misc1.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,12 @@ open_line(
14271427
/* Postpone calling changed_lines(), because it would mess up folding
14281428
* with markers.
14291429
* Skip mark_adjust when adding a line after the last one, there can't
1430-
* be marks there. */
1431-
if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count)
1430+
* be marks there. But still needed in diff mode. */
1431+
if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count
1432+
#ifdef FEAT_DIFF
1433+
|| curwin->w_p_diff
1434+
#endif
1435+
)
14321436
mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
14331437
did_append = TRUE;
14341438
}
@@ -2863,8 +2867,12 @@ appended_lines(linenr_T lnum, long count)
28632867
appended_lines_mark(linenr_T lnum, long count)
28642868
{
28652869
/* Skip mark_adjust when adding a line after the last one, there can't
2866-
* be marks there. */
2867-
if (lnum + count < curbuf->b_ml.ml_line_count)
2870+
* be marks there. But it's still needed in diff mode. */
2871+
if (lnum + count < curbuf->b_ml.ml_line_count
2872+
#ifdef FEAT_DIFF
2873+
|| curwin->w_p_diff
2874+
#endif
2875+
)
28682876
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
28692877
changed_lines(lnum + 1, 0, lnum + 1, count);
28702878
}

src/ops.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3927,9 +3927,13 @@ do_put(
39273927
curbuf->b_op_start.lnum++;
39283928
}
39293929
/* Skip mark_adjust when adding lines after the last one, there
3930-
* can't be marks there. */
3930+
* can't be marks there. But still needed in diff mode. */
39313931
if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines
3932-
< curbuf->b_ml.ml_line_count)
3932+
< curbuf->b_ml.ml_line_count
3933+
#ifdef FEAT_DIFF
3934+
|| curwin->w_p_diff
3935+
#endif
3936+
)
39333937
mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR),
39343938
(linenr_T)MAXLNUM, nr_lines, 0L);
39353939

@@ -6311,7 +6315,7 @@ write_viminfo_registers(FILE *fp)
63116315

63126316
/*
63136317
* Routine to export any final X selection we had to the environment
6314-
* so that the text is still available after vim has exited. X selections
6318+
* so that the text is still available after Vim has exited. X selections
63156319
* only exist while the owning application exists, so we write to the
63166320
* permanent (while X runs) store CUT_BUFFER0.
63176321
* Dump the CLIPBOARD selection if we own it (it's logically the more

src/testdir/test_diffmode.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,23 @@ func Test_diff_nomodifiable()
347347
call assert_fails('norm do', 'E21:')
348348
%bwipe!
349349
endfunc
350+
351+
func Test_diff_lastline()
352+
enew!
353+
only!
354+
call setline(1, ['This is a ', 'line with five ', 'rows'])
355+
diffthis
356+
botright vert new
357+
call setline(1, ['This is', 'a line with ', 'four rows'])
358+
diffthis
359+
1
360+
call feedkeys("Je a\<CR>", 'tx')
361+
call feedkeys("Je a\<CR>", 'tx')
362+
let w1lines = winline()
363+
wincmd w
364+
$
365+
let w2lines = winline()
366+
call assert_equal(w2lines, w1lines)
367+
bwipe!
368+
bwipe!
369+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
421,
767769
/**/
768770
420,
769771
/**/

0 commit comments

Comments
 (0)