Skip to content

Commit

Permalink
Initial work to account for folds.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Dec 20, 2020
1 parent c5d7d5e commit 44997ad
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions autoload/scrollview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@ function! s:GetVariable(name, winnr, ...) abort
return l:default
endfunction

" Returns the count of visible lines between (inclusive) the specified start
" and end lines, in the current window. A closed fold counts as one visible
" line.
" TODO: Port to Lua to execute faster, or alternatively use Vim's built-in
" fold movement commands to figure out the count of visible lines.
function! s:VisibleLineCount(start, end) abort
let l:result = 0
let l:line = a:start
while l:line <=# a:end
let l:result += 1
let l:foldclosedend = foldclosedend(l:line)
if l:foldclosedend !=# -1
let l:line = l:foldclosedend
endif
let l:line += 1
endwhile
return l:result
endfunction

" Same as VisibleLineCount, but operates on the specified window, as opposed
" to the current window.
function! s:WinVisibleLineCount(winid, start, end) abort
let l:command =
\ 'let l:result = s:VisibleLineCount(' . a:start . ', ' . a:end . ')'
let l:result = s:WinExecute(a:winid, [l:command])
return l:result
endfunction

" Calculates the bar position for the specified window. Returns a dictionary
" with a height, row, and col.
function! s:CalculatePosition(winnr) abort
Expand Down

0 comments on commit 44997ad

Please sign in to comment.