0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

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)
This commit is contained in:
Bram Moolenaar
2019-12-30 21:59:03 +01:00
parent 08b28b7ad5
commit efcc329020
3 changed files with 51 additions and 28 deletions

View File

@@ -2661,6 +2661,11 @@ ExpandBufnames(
*num_file = 0; // return values in case of FAIL *num_file = 0; // return values in case of FAIL
*file = NULL; *file = NULL;
#ifdef FEAT_DIFF
if ((options & BUF_DIFF_FILTER) && !curwin->w_p_diff)
return FAIL;
#endif
// Make a copy of "pat" and change "^" to "\(^\|[\/]\)". // Make a copy of "pat" and change "^" to "\(^\|[\/]\)".
if (*pat == '^') if (*pat == '^')
{ {
@@ -2706,8 +2711,7 @@ ExpandBufnames(
if (options & BUF_DIFF_FILTER) if (options & BUF_DIFF_FILTER)
// Skip buffers not suitable for // Skip buffers not suitable for
// :diffget or :diffput completion. // :diffget or :diffput completion.
if (buf == curbuf if (buf == curbuf || !diff_mode_buf(buf))
|| !diff_mode_buf(curbuf) || !diff_mode_buf(buf))
continue; continue;
#endif #endif

View File

@@ -242,43 +242,60 @@ func Test_diffput_two()
bwipe! b bwipe! b
endfunc endfunc
func Test_diffget_diffput_completion()
new Xdiff1 | diffthis
new Xdiff2 | diffthis
new Xdiff3 | diffthis
new Xdiff4
" :diffput and :diffget completes names of buffers which " :diffput and :diffget completes names of buffers which
" are in diff mode and which are different then current buffer. " are in diff mode and which are different then current buffer.
b Xdiff1 " No completion when the current window is not in diff mode.
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') func Test_diffget_diffput_completion()
call assert_equal('"diffput Xdiff2 Xdiff3', @:) e Xdiff1 | diffthis
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') botright new Xdiff2
call assert_equal('"diffget Xdiff2 Xdiff3', @:) botright new Xdiff3 | split | diffthis
call assert_equal(['Xdiff2', 'Xdiff3'], getcompletion('', 'diff_buffer')) botright new Xdiff4 | diffthis
b Xdiff2 wincmd t
call assert_equal('Xdiff1', bufname('%'))
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffput Xdiff1 Xdiff3', @:) call assert_equal('"diffput Xdiff3 Xdiff4', @:)
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffget Xdiff1 Xdiff3', @:) call assert_equal('"diffget Xdiff3 Xdiff4', @:)
call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer')) call assert_equal(['Xdiff3', 'Xdiff4'], getcompletion('', 'diff_buffer'))
b Xdiff3 " Xdiff2 is not in diff mode, so no completion for :diffput, :diffget
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') wincmd j
call assert_equal('"diffput Xdiff1 Xdiff2', @:) call assert_equal('Xdiff2', bufname('%'))
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffget Xdiff1 Xdiff2', @:)
call assert_equal(['Xdiff1', 'Xdiff2'], getcompletion('', 'diff_buffer'))
" No completion when in Xdiff4, it's not in diff mode.
b Xdiff4
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffput ', @:) call assert_equal('"diffput ', @:)
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffget ', @:) call assert_equal('"diffget ', @:)
call assert_equal([], getcompletion('', 'diff_buffer')) call assert_equal([], getcompletion('', 'diff_buffer'))
" Xdiff3 is split in 2 windows, only the top one is in diff mode.
" So completion of :diffput :diffget only happens in the top window.
wincmd j
call assert_equal('Xdiff3', bufname('%'))
call assert_equal(1, &diff)
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffput Xdiff1 Xdiff4', @:)
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffget Xdiff1 Xdiff4', @:)
call assert_equal(['Xdiff1', 'Xdiff4'], getcompletion('', 'diff_buffer'))
wincmd j
call assert_equal('Xdiff3', bufname('%'))
call assert_equal(0, &diff)
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffput ', @:)
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffget ', @:)
call assert_equal([], getcompletion('', 'diff_buffer'))
wincmd j
call assert_equal('Xdiff4', bufname('%'))
call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffput Xdiff1 Xdiff3', @:)
call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"diffget Xdiff1 Xdiff3', @:)
call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer'))
%bwipe %bwipe
endfunc endfunc

View File

@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
64,
/**/ /**/
63, 63,
/**/ /**/