Skip to content

Commit efcc329

Browse files
committed
patch 8.2.0064: diffmode completion doesn't use per-window setting
Problem: Diffmode completion doesn't use per-window setting. Solution: Check if a window is in diff mode. (Dominique Pell, closes #5419)
1 parent 08b28b7 commit efcc329

3 files changed

Lines changed: 46 additions & 23 deletions

File tree

src/buffer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,6 +2661,11 @@ ExpandBufnames(
26612661
*num_file = 0; // return values in case of FAIL
26622662
*file = NULL;
26632663

2664+
#ifdef FEAT_DIFF
2665+
if ((options & BUF_DIFF_FILTER) && !curwin->w_p_diff)
2666+
return FAIL;
2667+
#endif
2668+
26642669
// Make a copy of "pat" and change "^" to "\(^\|[\/]\)".
26652670
if (*pat == '^')
26662671
{
@@ -2706,8 +2711,7 @@ ExpandBufnames(
27062711
if (options & BUF_DIFF_FILTER)
27072712
// Skip buffers not suitable for
27082713
// :diffget or :diffput completion.
2709-
if (buf == curbuf
2710-
|| !diff_mode_buf(curbuf) || !diff_mode_buf(buf))
2714+
if (buf == curbuf || !diff_mode_buf(buf))
27112715
continue;
27122716
#endif
27132717

src/testdir/test_diffmode.vim

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -242,43 +242,60 @@ func Test_diffput_two()
242242
bwipe! b
243243
endfunc
244244

245+
" :diffput and :diffget completes names of buffers which
246+
" are in diff mode and which are different then current buffer.
247+
" No completion when the current window is not in diff mode.
245248
func Test_diffget_diffput_completion()
246-
new Xdiff1 | diffthis
247-
new Xdiff2 | diffthis
248-
new Xdiff3 | diffthis
249-
new Xdiff4
250-
251-
" :diffput and :diffget completes names of buffers which
252-
" are in diff mode and which are different then current buffer.
253-
b Xdiff1
249+
e Xdiff1 | diffthis
250+
botright new Xdiff2
251+
botright new Xdiff3 | split | diffthis
252+
botright new Xdiff4 | diffthis
253+
254+
wincmd t
255+
call assert_equal('Xdiff1', bufname('%'))
254256
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
255-
call assert_equal('"diffput Xdiff2 Xdiff3', @:)
257+
call assert_equal('"diffput Xdiff3 Xdiff4', @:)
256258
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
257-
call assert_equal('"diffget Xdiff2 Xdiff3', @:)
258-
call assert_equal(['Xdiff2', 'Xdiff3'], getcompletion('', 'diff_buffer'))
259+
call assert_equal('"diffget Xdiff3 Xdiff4', @:)
260+
call assert_equal(['Xdiff3', 'Xdiff4'], getcompletion('', 'diff_buffer'))
259261

260-
b Xdiff2
262+
" Xdiff2 is not in diff mode, so no completion for :diffput, :diffget
263+
wincmd j
264+
call assert_equal('Xdiff2', bufname('%'))
261265
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
262-
call assert_equal('"diffput Xdiff1 Xdiff3', @:)
266+
call assert_equal('"diffput ', @:)
263267
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
264-
call assert_equal('"diffget Xdiff1 Xdiff3', @:)
265-
call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer'))
268+
call assert_equal('"diffget ', @:)
269+
call assert_equal([], getcompletion('', 'diff_buffer'))
266270

267-
b Xdiff3
271+
" Xdiff3 is split in 2 windows, only the top one is in diff mode.
272+
" So completion of :diffput :diffget only happens in the top window.
273+
wincmd j
274+
call assert_equal('Xdiff3', bufname('%'))
275+
call assert_equal(1, &diff)
268276
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
269-
call assert_equal('"diffput Xdiff1 Xdiff2', @:)
277+
call assert_equal('"diffput Xdiff1 Xdiff4', @:)
270278
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
271-
call assert_equal('"diffget Xdiff1 Xdiff2', @:)
272-
call assert_equal(['Xdiff1', 'Xdiff2'], getcompletion('', 'diff_buffer'))
279+
call assert_equal('"diffget Xdiff1 Xdiff4', @:)
280+
call assert_equal(['Xdiff1', 'Xdiff4'], getcompletion('', 'diff_buffer'))
273281

274-
" No completion when in Xdiff4, it's not in diff mode.
275-
b Xdiff4
282+
wincmd j
283+
call assert_equal('Xdiff3', bufname('%'))
284+
call assert_equal(0, &diff)
276285
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
277286
call assert_equal('"diffput ', @:)
278287
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
279288
call assert_equal('"diffget ', @:)
280289
call assert_equal([], getcompletion('', 'diff_buffer'))
281290

291+
wincmd j
292+
call assert_equal('Xdiff4', bufname('%'))
293+
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
294+
call assert_equal('"diffput Xdiff1 Xdiff3', @:)
295+
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
296+
call assert_equal('"diffget Xdiff1 Xdiff3', @:)
297+
call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer'))
298+
282299
%bwipe
283300
endfunc
284301

src/version.c

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

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
64,
745747
/**/
746748
63,
747749
/**/

0 commit comments

Comments
 (0)