mirror of
https://github.com/gryf/tagbar.git
synced 2025-12-17 11:30:28 +01:00
Try to jump to the correct line after a file has been changed but not saved, closes #20
This commit is contained in:
@@ -1731,7 +1731,7 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo)
|
||||
let dollar = ''
|
||||
endif
|
||||
let pattern = strpart(pattern, start, end - start)
|
||||
let taginfo.pattern = '\V\^' . pattern . dollar
|
||||
let taginfo.pattern = '\V\^\C' . pattern . dollar
|
||||
let prototype = substitute(pattern, '^[[:space:]]\+', '', '')
|
||||
let prototype = substitute(prototype, '[[:space:]]\+$', '', '')
|
||||
let taginfo.prototype = prototype
|
||||
@@ -2362,6 +2362,23 @@ function! s:JumpToTag(stay_in_tagbar)
|
||||
" with the same name are defined in different scopes (e.g. classes)
|
||||
execute taginfo.fields.line
|
||||
|
||||
" If the file has been changed but not saved, the tag may not be on the
|
||||
" saved line anymore, so search for it in the vicinity of the saved line
|
||||
if match(getline('.'), taginfo.pattern) == -1
|
||||
let interval = 1
|
||||
let forward = 1
|
||||
while search(taginfo.pattern, 'W' . forward ? '' : 'b') == 0
|
||||
if !forward
|
||||
if interval > line('$')
|
||||
break
|
||||
else
|
||||
let interval = interval * 2
|
||||
endif
|
||||
endif
|
||||
let forward = !forward
|
||||
endwhile
|
||||
endif
|
||||
|
||||
" Center the tag in the window
|
||||
normal! z.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user