diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-01-24 07:29:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 07:29:33 +0800 |
commit | 65bfa86efeeb2ec18ba82fd821ffd4c8f97fcd2b (patch) | |
tree | bf5999ea603cd484c19148687a0dd83c0d8fecc1 | |
parent | 6cbfe454542ff498a84b22f0aff1bf215e883485 (diff) | |
download | rneovim-65bfa86efeeb2ec18ba82fd821ffd4c8f97fcd2b.tar.gz rneovim-65bfa86efeeb2ec18ba82fd821ffd4c8f97fcd2b.tar.bz2 rneovim-65bfa86efeeb2ec18ba82fd821ffd4c8f97fcd2b.zip |
vim-patch:9.1.0046: :drop does not re-use empty buffer (#27165)
Problem: :drop does not re-use empty buffer
(Rocco Mao)
Solution: Make :drop re-use an empty buffer
(Rocco Mao)
fixes: vim/vim#13851
closes: vim/vim#13881
https://github.com/vim/vim/commit/f96dc8d07f752ddd96d1447d85278a85255a1462
Co-authored-by: Rocco Mao <dapeng.mao@qq.com>
-rw-r--r-- | src/nvim/arglist.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 6 | ||||
-rw-r--r-- | test/functional/core/remote_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ex_cmds/drop_spec.lua | 2 | ||||
-rw-r--r-- | test/old/testdir/test_excmd.vim | 22 | ||||
-rw-r--r-- | test/old/testdir/test_tabpage.vim | 72 |
6 files changed, 93 insertions, 15 deletions
diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 921d56ed78..e9108f72cc 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -477,7 +477,7 @@ static int do_arglist(char *str, int what, int after, bool will_edit) /// Redefine the argument list. void set_arglist(char *str) { - do_arglist(str, AL_SET, 0, false); + do_arglist(str, AL_SET, 0, true); } /// @return true if window "win" is editing the file at the current argument diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 234a927291..842f8a4297 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -799,8 +799,7 @@ static void script_host_do_range(char *name, exarg_T *eap) } /// ":drop" -/// Opens the first argument in a window. When there are two or more arguments -/// the argument list is redefined. +/// Opens the first argument in a window, and the argument list is redefined. void ex_drop(exarg_T *eap) { bool split = false; @@ -825,6 +824,8 @@ void ex_drop(exarg_T *eap) // edited in a window yet. It's like ":tab all" but without closing // windows or tabs. ex_all(eap); + cmdmod.cmod_tab = 0; + ex_rewind(eap); return; } @@ -845,6 +846,7 @@ void ex_drop(exarg_T *eap) buf_check_timestamp(curbuf); curbuf->b_p_ar = save_ar; } + ex_rewind(eap); return; } } diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index a48534f51b..caff06f6ab 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -81,7 +81,7 @@ describe('Remote', function() it('edit a single file', function() eq({ '', '' }, run_remote('--remote', fname)) expect(contents) - eq(2, #fn.getbufinfo()) + eq(1, #fn.getbufinfo()) end) it('tab edit a single file with a non-changed buffer', function() @@ -102,7 +102,7 @@ describe('Remote', function() expect(contents) command('next') expect(other_contents) - eq(3, #fn.getbufinfo()) + eq(2, #fn.getbufinfo()) end) it('send keys', function() diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua index c78928f7a1..cbda5aac98 100644 --- a/test/functional/ex_cmds/drop_spec.lua +++ b/test/functional/ex_cmds/drop_spec.lua @@ -38,7 +38,7 @@ describe(':drop', function() │^ | {0:~ }│{0:~ }|*7 {2:tmp2 }{1:tmp1 }| - :drop tmp1 | + "tmp1" [New] | ]]) end) diff --git a/test/old/testdir/test_excmd.vim b/test/old/testdir/test_excmd.vim index c729ff4929..b7356c22fa 100644 --- a/test/old/testdir/test_excmd.vim +++ b/test/old/testdir/test_excmd.vim @@ -90,23 +90,31 @@ endfunc " Test for the :drop command func Test_drop_cmd() - call writefile(['L1', 'L2'], 'Xfile') + call writefile(['L1', 'L2'], 'Xdropfile', 'D') + " Test for reusing the current buffer enew | only - drop Xfile + let expected_nr = bufnr() + drop Xdropfile + call assert_equal(expected_nr, bufnr()) call assert_equal('L2', getline(2)) " Test for switching to an existing window below new - drop Xfile + drop Xdropfile call assert_equal(1, winnr()) - " Test for splitting the current window + " Test for splitting the current window (set nohidden) enew | only set modified - drop Xfile + drop Xdropfile call assert_equal(2, winnr('$')) + " Not splitting the current window even if modified (set hidden) + set hidden + enew | only + set modified + drop Xdropfile + call assert_equal(1, winnr('$')) " Check for setting the argument list - call assert_equal(['Xfile'], argv()) + call assert_equal(['Xdropfile'], argv()) enew | only! - call delete('Xfile') endfunc " Test for the :append command diff --git a/test/old/testdir/test_tabpage.vim b/test/old/testdir/test_tabpage.vim index d3393af04b..d335f3c1ee 100644 --- a/test/old/testdir/test_tabpage.vim +++ b/test/old/testdir/test_tabpage.vim @@ -164,6 +164,74 @@ func Test_tabpage_drop() bwipe! bwipe! call assert_equal(1, tabpagenr('$')) + + call assert_equal(1, winnr('$')) + call assert_equal('', bufname('')) + call writefile(['L1', 'L2'], 'Xdropfile', 'D') + + " Test for ':tab drop single-file': reuse current buffer + let expected_nr = bufnr() + tab drop Xdropfile + call assert_equal(1, tabpagenr('$')) + call assert_equal(expected_nr, bufnr()) + call assert_equal('L2', getline(2)) + bwipe! + + " Test for ':tab drop single-file': not reuse modified buffer + set modified + let expected_nr = bufnr() + 1 + tab drop Xdropfile + call assert_equal(2, tabpagenr()) + call assert_equal(2, tabpagenr('$')) + call assert_equal(expected_nr, bufnr()) + call assert_equal('L2', getline(2)) + bwipe! + + " Test for ':tab drop single-file': multiple tabs already exist + tab split f2 + tab split f3 + let expected_nr = bufnr() + 1 + tab drop Xdropfile + call assert_equal(4, tabpagenr()) + call assert_equal(4, tabpagenr('$')) + call assert_equal(expected_nr, bufnr()) + call assert_equal('L2', getline(2)) + %bwipe! + + " Test for ':tab drop multi-files': reuse current buffer + let expected_nr = bufnr() + tab drop Xdropfile f1 f2 f3 + call assert_equal(1, tabpagenr()) + call assert_equal(4, tabpagenr('$')) + call assert_equal(expected_nr, bufnr()) + call assert_equal('L2', getline(2)) + %bwipe! + + " Test for ':tab drop multi-files': not reuse modified buffer + set modified + let expected_nr = bufnr() + 1 + tab drop Xdropfile f1 f2 f3 + call assert_equal(2, tabpagenr()) + call assert_equal(5, tabpagenr('$')) + call assert_equal(expected_nr, bufnr()) + call assert_equal('L2', getline(2)) + %bwipe! + + " Test for ':tab drop multi-files': multiple tabs already exist + tab split f2 + tab split f3 + let expected_nr = bufnr() + 1 + tab drop a b c + call assert_equal(4, tabpagenr()) + call assert_equal(6, tabpagenr('$')) + call assert_equal(expected_nr, bufnr()) + let expected_nr = bufnr() + 3 + tab drop Xdropfile f1 f2 f3 + call assert_equal(5, tabpagenr()) + call assert_equal(8, tabpagenr('$')) + call assert_equal(expected_nr, bufnr()) + call assert_equal('L2', getline(2)) + %bwipe! endfunc " Test autocommands @@ -260,14 +328,14 @@ function Test_tabpage_with_autocmd_tab_drop() let s:li = [] tab drop test1 - call assert_equal(['BufLeave', 'BufEnter'], s:li) + call assert_equal(['BufEnter'], s:li) let s:li = [] tab drop test2 test3 call assert_equal([ \ 'TabLeave', 'TabEnter', 'TabLeave', 'TabEnter', \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter', - \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li) + \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter', 'BufEnter'], s:li) autocmd! TestTabpageGroup augroup! TestTabpageGroup |