vim-patch:9.1.1949: :stag does not use 'swichtbuf' option

Problem:  :stag does not use 'swichtbuf' option, though the
          documentation states differently
          (Christian Brabandt)
Solution: Respect 'switchbuf' option (Yegappan Lakshmanan).

related: vim/vim#18845
closes: vim/vim#18856

efc7509be2

Cherry-pick some test_tagjump.vim changes from patches 9.0.{0363,0767}.

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2025-12-04 08:31:06 +08:00
parent 551bb63d44
commit 69f4fd84aa
3 changed files with 60 additions and 36 deletions

View File

@@ -871,13 +871,15 @@ the buffer. The result is that all buffers will use the 'encoding' encoding
*:sta* *:stag* *:sta* *:stag*
:sta[g][!] [tagname] :sta[g][!] [tagname]
Does ":tag[!] [tagname]" and splits the window for the found Does ":tag[!] [tagname]" and splits the window for the found
tag. See also |:tag|. tag. Refer to 'switchbuf' to jump to a tag in a vertically
split window or a new tab page. See also |:tag|.
CTRL-W ] *CTRL-W_]* *CTRL-W_CTRL-]* CTRL-W ] *CTRL-W_]* *CTRL-W_CTRL-]*
CTRL-W CTRL-] Split current window in two. Use identifier under cursor as a CTRL-W CTRL-] Split current window in two. Use identifier under cursor as a
tag and jump to it in the new upper window. tag and jump to it in the new upper window.
In Visual mode uses the Visually selected text as a tag. In Visual mode uses the Visually selected text as a tag.
Make new window N high. Make new window N high. Refer to 'switchbuf' to jump to a tag
in a vertically split window or a new tab page.
*CTRL-W_g]* *CTRL-W_g]*
CTRL-W g ] Split current window in two. Use identifier under cursor as a CTRL-W g ] Split current window in two. Use identifier under cursor as a

View File

@@ -2863,6 +2863,17 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, bool keep_help)
} }
if (getfile_result == GETFILE_UNUSED if (getfile_result == GETFILE_UNUSED
&& (postponed_split || cmdmod.cmod_tab != 0)) { && (postponed_split || cmdmod.cmod_tab != 0)) {
if (swb_flags & kOptSwbFlagVsplit) {
// If 'switchbuf' contains 'vsplit', then use a new vertically
// split window.
cmdmod.cmod_split |= WSP_VERT;
}
if (swb_flags & kOptSwbFlagNewtab) {
// If 'switchbuf' contains 'newtab', then use a new tabpage
cmdmod.cmod_tab = tabpage_index(curtab) + 1;
}
if (win_split(postponed_split > 0 ? postponed_split : 0, if (win_split(postponed_split > 0 ? postponed_split : 0,
postponed_split_flags) == FAIL) { postponed_split_flags) == FAIL) {
RedrawingDisabled--; RedrawingDisabled--;

View File

@@ -15,20 +15,20 @@ endfunc
func Test_ptjump() func Test_ptjump()
CheckFeature quickfix CheckFeature quickfix
set tags=Xtags set tags=Xpttags
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "one\tXfile\t1", \ "one\tXptfile\t1",
\ "three\tXfile\t3", \ "three\tXptfile\t3",
\ "two\tXfile\t2"], \ "two\tXptfile\t2"],
\ 'Xtags') \ 'Xpttags', 'D')
call writefile(['one', 'two', 'three'], 'Xfile') call writefile(['one', 'two', 'three'], 'Xptfile', 'D')
%bw! %bw!
ptjump two ptjump two
call assert_equal(2, winnr()) call assert_equal(2, winnr())
wincmd p wincmd p
call assert_equal(1, &previewwindow) call assert_equal(1, &previewwindow)
call assert_equal('Xfile', expand("%:p:t")) call assert_equal('Xptfile', expand("%:p:t"))
call assert_equal(2, line('.')) call assert_equal(2, line('.'))
call assert_equal(2, winnr('$')) call assert_equal(2, winnr('$'))
call assert_equal(1, winnr()) call assert_equal(1, winnr())
@@ -38,7 +38,7 @@ func Test_ptjump()
call assert_equal(2, winnr()) call assert_equal(2, winnr())
wincmd p wincmd p
call assert_equal(1, &previewwindow) call assert_equal(1, &previewwindow)
call assert_equal('Xfile', expand("%:p:t")) call assert_equal('Xptfile', expand("%:p:t"))
call assert_equal(3, line('.')) call assert_equal(3, line('.'))
call assert_equal(2, winnr('$')) call assert_equal(2, winnr('$'))
call assert_equal(1, winnr()) call assert_equal(1, winnr())
@@ -48,8 +48,6 @@ func Test_ptjump()
call assert_equal(5, winheight(0)) call assert_equal(5, winheight(0))
close close
call delete('Xtags')
call delete('Xfile')
set tags& set tags&
endfunc endfunc
@@ -60,25 +58,24 @@ func Test_cancel_ptjump()
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "word\tfile1\tcmd1", \ "word\tfile1\tcmd1",
\ "word\tfile2\tcmd2"], \ "word\tfile2\tcmd2"],
\ 'Xtags') \ 'Xtags', 'D')
only! only!
call feedkeys(":ptjump word\<CR>\<CR>", "xt") call feedkeys(":ptjump word\<CR>\<CR>", "xt")
help help
call assert_equal(2, winnr('$')) call assert_equal(2, winnr('$'))
call delete('Xtags')
set tags& set tags&
quit quit
endfunc endfunc
func Test_static_tagjump() func Test_static_tagjump()
set tags=Xtags set tags=Xtjtags
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "one\tXfile1\t/^one/;\"\tf\tfile:\tsignature:(void)", \ "one\tXtjfile1\t/^one/;\"\tf\tfile:\tsignature:(void)",
\ "word\tXfile2\tcmd2"], \ "word\tXtjfile2\tcmd2"],
\ 'Xtags') \ 'Xtjtags', 'D')
new Xfile1 new Xtjfile1
call setline(1, ['empty', 'one()', 'empty']) call setline(1, ['empty', 'one()', 'empty'])
write write
tag one tag one
@@ -86,19 +83,18 @@ func Test_static_tagjump()
bwipe! bwipe!
set tags& set tags&
call delete('Xtags') call delete('Xtjfile1')
call delete('Xfile1')
endfunc endfunc
func Test_duplicate_tagjump() func Test_duplicate_tagjump()
set tags=Xtags set tags=Xdttags
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "thesame\tXfile1\t1;\"\td\tfile:", \ "thesame\tXdtfile1\t1;\"\td\tfile:",
\ "thesame\tXfile1\t2;\"\td\tfile:", \ "thesame\tXdtfile1\t2;\"\td\tfile:",
\ "thesame\tXfile1\t3;\"\td\tfile:", \ "thesame\tXdtfile1\t3;\"\td\tfile:",
\ ], \ ],
\ 'Xtags') \ 'Xdttags', 'D')
new Xfile1 new Xdtfile1
call setline(1, ['thesame one', 'thesame two', 'thesame three']) call setline(1, ['thesame one', 'thesame two', 'thesame three'])
write write
tag thesame tag thesame
@@ -110,19 +106,18 @@ func Test_duplicate_tagjump()
bwipe! bwipe!
set tags& set tags&
call delete('Xtags') call delete('Xdtfile1')
call delete('Xfile1')
endfunc endfunc
func Test_tagjump_switchbuf() func Test_tagjump_switchbuf()
CheckFeature quickfix CheckFeature quickfix
set tags=Xtags set tags=Xswtags
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "second\tXfile1\t2", \ "second\tXsbfile1\t2",
\ "third\tXfile1\t3",], \ "third\tXsbfile1\t3",],
\ 'Xtags') \ 'Xswtags', 'D')
call writefile(['first', 'second', 'third'], 'Xfile1') call writefile(['first', 'second', 'third'], 'Xsbfile1', 'D')
enew | only enew | only
set switchbuf= set switchbuf=
@@ -150,11 +145,27 @@ func Test_tagjump_switchbuf()
1tabnext | stag third 1tabnext | stag third
call assert_equal(2, tabpagenr('$')) call assert_equal(2, tabpagenr('$'))
call assert_equal(3, line('.')) call assert_equal(3, line('.'))
tabonly
" use a vertically split window
enew | only
set switchbuf=vsplit
stag third
call assert_equal(2, winnr('$'))
call assert_equal(1, winnr())
call assert_equal(3, line('.'))
call assert_equal(['row', [['leaf', win_getid(1)], ['leaf', win_getid(2)]]], winlayout())
" jump to a tag in a new tabpage
enew | only
set switchbuf=newtab
stag second
call assert_equal(2, tabpagenr('$'))
call assert_equal(2, tabpagenr())
call assert_equal(2, line('.'))
tabclose! tabclose!
enew | only enew | only
call delete('Xfile1')
call delete('Xtags')
set tags& set tags&
set switchbuf&vim set switchbuf&vim
endfunc endfunc