mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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
f96dc8d07f
Co-authored-by: Rocco Mao <dapeng.mao@qq.com>
This commit is contained in:
parent
6cbfe45454
commit
65bfa86efe
@ -477,7 +477,7 @@ static int do_arglist(char *str, int what, int after, bool will_edit)
|
|||||||
/// Redefine the argument list.
|
/// Redefine the argument list.
|
||||||
void set_arglist(char *str)
|
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
|
/// @return true if window "win" is editing the file at the current argument
|
||||||
|
@ -799,8 +799,7 @@ static void script_host_do_range(char *name, exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// ":drop"
|
/// ":drop"
|
||||||
/// Opens the first argument in a window. When there are two or more arguments
|
/// Opens the first argument in a window, and the argument list is redefined.
|
||||||
/// the argument list is redefined.
|
|
||||||
void ex_drop(exarg_T *eap)
|
void ex_drop(exarg_T *eap)
|
||||||
{
|
{
|
||||||
bool split = false;
|
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
|
// edited in a window yet. It's like ":tab all" but without closing
|
||||||
// windows or tabs.
|
// windows or tabs.
|
||||||
ex_all(eap);
|
ex_all(eap);
|
||||||
|
cmdmod.cmod_tab = 0;
|
||||||
|
ex_rewind(eap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,6 +846,7 @@ void ex_drop(exarg_T *eap)
|
|||||||
buf_check_timestamp(curbuf);
|
buf_check_timestamp(curbuf);
|
||||||
curbuf->b_p_ar = save_ar;
|
curbuf->b_p_ar = save_ar;
|
||||||
}
|
}
|
||||||
|
ex_rewind(eap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ describe('Remote', function()
|
|||||||
it('edit a single file', function()
|
it('edit a single file', function()
|
||||||
eq({ '', '' }, run_remote('--remote', fname))
|
eq({ '', '' }, run_remote('--remote', fname))
|
||||||
expect(contents)
|
expect(contents)
|
||||||
eq(2, #fn.getbufinfo())
|
eq(1, #fn.getbufinfo())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('tab edit a single file with a non-changed buffer', function()
|
it('tab edit a single file with a non-changed buffer', function()
|
||||||
@ -102,7 +102,7 @@ describe('Remote', function()
|
|||||||
expect(contents)
|
expect(contents)
|
||||||
command('next')
|
command('next')
|
||||||
expect(other_contents)
|
expect(other_contents)
|
||||||
eq(3, #fn.getbufinfo())
|
eq(2, #fn.getbufinfo())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('send keys', function()
|
it('send keys', function()
|
||||||
|
@ -38,7 +38,7 @@ describe(':drop', function()
|
|||||||
│^ |
|
│^ |
|
||||||
{0:~ }│{0:~ }|*7
|
{0:~ }│{0:~ }|*7
|
||||||
{2:tmp2 }{1:tmp1 }|
|
{2:tmp2 }{1:tmp1 }|
|
||||||
:drop tmp1 |
|
"tmp1" [New] |
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -90,23 +90,31 @@ endfunc
|
|||||||
|
|
||||||
" Test for the :drop command
|
" Test for the :drop command
|
||||||
func Test_drop_cmd()
|
func Test_drop_cmd()
|
||||||
call writefile(['L1', 'L2'], 'Xfile')
|
call writefile(['L1', 'L2'], 'Xdropfile', 'D')
|
||||||
|
" Test for reusing the current buffer
|
||||||
enew | only
|
enew | only
|
||||||
drop Xfile
|
let expected_nr = bufnr()
|
||||||
|
drop Xdropfile
|
||||||
|
call assert_equal(expected_nr, bufnr())
|
||||||
call assert_equal('L2', getline(2))
|
call assert_equal('L2', getline(2))
|
||||||
" Test for switching to an existing window
|
" Test for switching to an existing window
|
||||||
below new
|
below new
|
||||||
drop Xfile
|
drop Xdropfile
|
||||||
call assert_equal(1, winnr())
|
call assert_equal(1, winnr())
|
||||||
" Test for splitting the current window
|
" Test for splitting the current window (set nohidden)
|
||||||
enew | only
|
enew | only
|
||||||
set modified
|
set modified
|
||||||
drop Xfile
|
drop Xdropfile
|
||||||
call assert_equal(2, winnr('$'))
|
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
|
" Check for setting the argument list
|
||||||
call assert_equal(['Xfile'], argv())
|
call assert_equal(['Xdropfile'], argv())
|
||||||
enew | only!
|
enew | only!
|
||||||
call delete('Xfile')
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for the :append command
|
" Test for the :append command
|
||||||
|
@ -164,6 +164,74 @@ func Test_tabpage_drop()
|
|||||||
bwipe!
|
bwipe!
|
||||||
bwipe!
|
bwipe!
|
||||||
call assert_equal(1, tabpagenr('$'))
|
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
|
endfunc
|
||||||
|
|
||||||
" Test autocommands
|
" Test autocommands
|
||||||
@ -260,14 +328,14 @@ function Test_tabpage_with_autocmd_tab_drop()
|
|||||||
|
|
||||||
let s:li = []
|
let s:li = []
|
||||||
tab drop test1
|
tab drop test1
|
||||||
call assert_equal(['BufLeave', 'BufEnter'], s:li)
|
call assert_equal(['BufEnter'], s:li)
|
||||||
|
|
||||||
let s:li = []
|
let s:li = []
|
||||||
tab drop test2 test3
|
tab drop test2 test3
|
||||||
call assert_equal([
|
call assert_equal([
|
||||||
\ 'TabLeave', 'TabEnter', 'TabLeave', 'TabEnter',
|
\ 'TabLeave', 'TabEnter', 'TabLeave', 'TabEnter',
|
||||||
\ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter',
|
\ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter',
|
||||||
\ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li)
|
\ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter', 'BufEnter'], s:li)
|
||||||
|
|
||||||
autocmd! TestTabpageGroup
|
autocmd! TestTabpageGroup
|
||||||
augroup! TestTabpageGroup
|
augroup! TestTabpageGroup
|
||||||
|
Loading…
Reference in New Issue
Block a user