Skip to content

Commit fa58c7d

Browse files
committed
Fixes preservim#650 Correct window positioning defaults (preservim#652)
* Fix for window positioning With default case having multiple vertically split windows, the tagbar window should open on the far right of the screen. When the feature in pull-request 630 was added, this behavior changed to open the tagbar window relative to the current window. This commit will fix that by allowing direct usage of the vim split options. Validated the following cases for the old default values. These all still behave the same way as prior to pull-request 630 when the tagbar is activated in the `active` window shown in the below examples: ``` " No options +-----------------------------------+ | preview | +--------+--------+--------+--------+ | edit | edit | edit | tagbar | | | active | | | +--------+--------+--------+--------+ " tagbar on left, preview above let g:tagbar_left = 1 +-----------------------------------+ | preview | +--------+--------+--------+--------+ | tagbar | edit | edit | edit | | | | active | | +--------+--------+--------+--------+ " tagbar on bottom, preview to right of tagbar let g:tagbar_vertical = 10 +--------+---------------+--------+ | edit | edit | edit | | | active | | | +-----+---------+ | | | tag | preview | | +--------+-----+---------+--------+ " tagbar on top, preview to the right of tagbar let g:tagbar_left = 1 let g:tagbar_vertical = 10 +--------+-----+---------+--------+ | edit | tag | preview | edit | | +-----+---------+ | | | edit | | | | active | | +--------+---------------+--------+ ``` New values also all validated using the following: ``` " Behaves the same as no options let g:tagbar_position = 'right' " Behaves the same as g:tagbar_left = 1 let g:tagbar_position = 'left' " Behaves the same as g:tagbar_vertical = <#> let g:tagbar_position = 'bottom' " Behaves the same as g:tagbar_left = 1 | g:tagbar_vertical = <#> let g:tagbar_position = 'top' ``` * preservim#650 - Fix typo in doc/tagbar.txt for g:tagbar_height option
1 parent 79b5107 commit fa58c7d

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

Diff for: autoload/tagbar.vim

+8-17
Original file line numberDiff line numberDiff line change
@@ -879,24 +879,15 @@ function! s:OpenWindow(flags) abort
879879
endif
880880

881881
let s:window_opening = 1
882-
if g:tagbar_position =~# '\v(bottom|right)'
883-
let openpos = 'rightbelow '
884-
else
885-
let openpos = 'leftabove '
886-
endif
887-
if g:tagbar_position =~# '\v(left|right)'
882+
if g:tagbar_position =~# 'vertical'
883+
let size = g:tagbar_width
888884
let mode = 'vertical '
889-
let width = g:tagbar_width
890885
else
886+
let size = g:tagbar_height
891887
let mode = ''
892-
if g:tagbar_height > 0
893-
let width = g:tagbar_height
894-
else
895-
let width = g:tagbar_vertical
896-
endif
897888
endif
898-
exe 'silent keepalt ' . openpos . mode . width . 'split ' . s:TagbarBufName()
899-
exe 'silent ' . mode . 'resize ' . width
889+
exe 'silent keepalt ' . g:tagbar_position . size . 'split ' . s:TagbarBufName()
890+
exe 'silent ' . mode . 'resize ' . size
900891
unlet s:window_opening
901892

902893
call s:InitWindow(autoclose)
@@ -2294,7 +2285,7 @@ function! s:ShowInPreviewWin() abort
22942285
" We want the preview window to be relative to the file window in normal
22952286
" (horizontal) mode, and relative to the Tagbar window in vertical mode,
22962287
" to make the best use of space.
2297-
if g:tagbar_position !~# '\v(top|bottom)'
2288+
if g:tagbar_position =~# 'vertical'
22982289
call s:GotoFileWindow(taginfo.fileinfo, 1)
22992290
call s:mark_window()
23002291
endif
@@ -2305,15 +2296,15 @@ function! s:ShowInPreviewWin() abort
23052296
silent execute
23062297
\ g:tagbar_previewwin_pos . ' pedit ' .
23072298
\ fnameescape(taginfo.fileinfo.fpath)
2308-
if g:tagbar_position =~# '\v(top|bottom)'
2299+
if g:tagbar_position !~# 'vertical'
23092300
silent execute 'vertical resize ' . g:tagbar_width
23102301
endif
23112302
" Remember that the preview window was opened by Tagbar so we can
23122303
" safely close it by ourselves
23132304
let s:pwin_by_tagbar = 1
23142305
endif
23152306

2316-
if g:tagbar_position =~# '\v(top|bottom)'
2307+
if g:tagbar_position !~# 'vertical'
23172308
call s:GotoFileWindow(taginfo.fileinfo, 1)
23182309
call s:mark_window()
23192310
endif

Diff for: doc/tagbar.txt

+19-17
Original file line numberDiff line numberDiff line change
@@ -446,24 +446,26 @@ configuration files.
446446

447447
*g:tagbar_position*
448448
g:tagbar_position~
449-
Default: 'right'
449+
Default: 'botright vertical'
450450

451-
By default the Tagbar window will be opened on the right-hand side of vim. Set
452-
this option to one of 'left', 'right', 'bottom', or 'top' to open in the
453-
corresponding position instead. This can be useful when activating Tagbar at
454-
the same time as another plugin which creates a new window. It allows for more
455-
granular control of the Tagbar position in relation to the current active
456-
window.
451+
By default the Tagbar window will be opened on the right-hand side of vim in a
452+
vertical split. Set this option to one of the standart vim split options such
453+
as 'topleft', 'botright', 'leftabove', or 'rightbelow' to open in the
454+
corresponding position instead. If desiring a vertically split window, then
455+
include a ' vertical' in the field value as well. This can be useful when
456+
activating Tagbar at the same time as another plugin which creates a new
457+
window. It allows for more granular control of the Tagbar position in
458+
relation to the current active window.
457459

458-
If set to 'top' of 'bottom', |g:tagbar_height| will be used to determine the
459-
window height for the tagbar window.
460+
If using a vertical split, |g:tagbar_width| will be used to determine the
461+
window width for the tagbar window. Else |g:tagbar_height| will be used to
462+
determine the window height for the tagbar window.
460463

461-
if set to 'left' or 'right', |g:tagbar_width| will be used to determine the
462-
window width for the tagbar window.
464+
See |split| for more details on window positioning.
463465

464466
Example:
465467
>
466-
let g:tagbar_position = 'left'
468+
let g:tagbar_position = 'leftabove'
467469
<
468470
*g:tagbar_left*
469471
g:tagbar_left~
@@ -505,20 +507,20 @@ Example:
505507
g:tagbar_height~
506508
Default: 0
507509

508-
If |g:tagbar_position| is set to 'bottom' or 'top', then this value is used to
509-
determine the height of the Tagbar window.
510-
See |g:tagbar_left| for configuring the position of the window.
510+
If |g:tagbar_position| does not include a 'vertical' option, then this
511+
value is used to determine the height of the Tagbar window.
511512

512513
Example:
513514
>
514515
let g:tagbar_height = 30
515516
<
517+
516518
*g:tagbar_width*
517519
g:tagbar_width~
518520
Default: 40
519521

520-
If |g:tagbar_position| is set to 'left' or 'right', then this value is used to
521-
determine the width of the Tagbar window in characters.
522+
If |g:tagbar_position| does include a 'vertical' options, then this value is
523+
used to determine the width of the Tagbar window in characters.
522524

523525
Example:
524526
>

Diff for: plugin/tagbar.vim

+18-8
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,37 @@ endfunction
5050

5151
function! s:setup_options() abort
5252
if exists('g:tagbar_position')
53-
if g:tagbar_position !~# '\v(top|bottom)'
54-
let previewwin_pos = 'topleft'
55-
else
53+
" Map older deprecated values to correct values
54+
if g:tagbar_position ==# 'top'
55+
let g:tagbar_position = 'leftabove'
56+
elseif g:tagbar_position ==# 'bottom'
57+
let g:tagbar_position = 'rightbelow'
58+
elseif g:tagbar_position ==# 'left'
59+
let g:tagbar_position = 'topleft vertical'
60+
elseif g:tagbar_position ==# 'right'
61+
let g:tagbar_position = 'botright vertical'
62+
endif
63+
if g:tagbar_position !~# 'vertical'
5664
let previewwin_pos = 'rightbelow vertical'
65+
else
66+
let previewwin_pos = 'topleft'
5767
endif
5868
let default_pos = g:tagbar_position
5969
else
6070
if exists('g:tagbar_vertical') && g:tagbar_vertical > 0
6171
let previewwin_pos = 'rightbelow vertical'
6272
if exists('g:tagbar_left') && g:tagbar_left
63-
let default_pos = 'top'
73+
let default_pos = 'leftabove'
6474
else
65-
let default_pos = 'bottom'
75+
let default_pos = 'rightbelow'
6676
endif
6777
let g:tagbar_height = g:tagbar_vertical
6878
elseif exists('g:tagbar_left') && g:tagbar_left
6979
let previewwin_pos = 'topleft'
70-
let default_pos = 'left'
80+
let default_pos = 'topleft vertical'
7181
else
7282
let previewwin_pos = 'topleft'
73-
let default_pos = 'right'
83+
let default_pos = 'botright vertical'
7484
endif
7585
endif
7686
let options = [
@@ -86,6 +96,7 @@ function! s:setup_options() abort
8696
\ ['height', 10],
8797
\ ['indent', 2],
8898
\ ['left', 0],
99+
\ ['position', default_pos],
89100
\ ['previewwin_pos', previewwin_pos],
90101
\ ['show_balloon', 1],
91102
\ ['show_visibility', 1],
@@ -94,7 +105,6 @@ function! s:setup_options() abort
94105
\ ['sort', 1],
95106
\ ['systemenc', &encoding],
96107
\ ['vertical', 0],
97-
\ ['position', default_pos],
98108
\ ['width', 40],
99109
\ ['zoomwidth', 1],
100110
\ ['silent', 0],

0 commit comments

Comments
 (0)