From f8587f106cb9f1313ac7efacd67f7b5a5897b6fd Mon Sep 17 00:00:00 2001 From: Martin Vuille Date: Sat, 27 Aug 2016 18:21:06 -0400 Subject: [PATCH] Keep cursor on same tag when toggle hide non-public --- autoload/tagbar.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 34e3f48..bee698f 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -3818,9 +3818,28 @@ endfunction " s:ToggleHideNonPublicTags() {{{2 function! s:ToggleHideNonPublicTags() abort + let fileinfo = s:known_files.getCurrent(0) + if empty(fileinfo) + return + endif + + " Save the tag the cursor is currently on + let curline = line('.') + let taginfo = s:GetTagInfo(curline, 0) + + match none + let g:tagbar_hide_nonpublic = !g:tagbar_hide_nonpublic call s:RenderKeepView() call s:SetStatusLine('current') + + " If we were on a tag before sorting then jump to it, otherwise restore + " the cursor to the current line + if !empty(taginfo) + execute taginfo.tline + else + execute curline + endif endfunction " s:ToggleAutoclose() {{{2