From c30410ae4d14c4340feb2c3e0a5b45fb9b9c7d24 Mon Sep 17 00:00:00 2001 From: Danila Mihailov Date: Sat, 27 Jun 2020 16:21:07 +0500 Subject: [PATCH] ignore moves over folds (#5) --- plugin/beacon.vim | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/plugin/beacon.vim b/plugin/beacon.vim index 0438395..32f4772 100644 --- a/plugin/beacon.vim +++ b/plugin/beacon.vim @@ -135,13 +135,32 @@ let s:prev_cursor = 0 " highlight position if cursor moved significally function! s:Cursor_moved() let l:cur = line(".") - let l:diff = l:cur - s:prev_cursor + let l:diff = abs(l:cur - s:prev_cursor) - if l:diff > g:beacon_minimal_jump || l:diff < g:beacon_minimal_jump * -1 - call s:Highlight_position(v:false) + if l:diff > g:beacon_minimal_jump + let l:prev_fold = foldclosed(s:prev_cursor) + let l:prev_fold_end = foldclosedend(s:prev_cursor) + let l:cur_fold = foldclosed(l:cur) + let l:cur_fold_end = foldclosedend(l:cur) + + " if we move over fold, substract fold lines from diff + if l:prev_fold > -1 && l:prev_fold_end > -1 + let l:diff -= l:prev_fold_end - l:prev_fold + endif + + " if we move over fold, substract fold lines from diff + if l:cur_fold > -1 && l:cur_fold_end > -1 + let l:diff -= l:cur_fold_end - l:cur_fold + endif + + " check diff again before highlight + if l:diff > g:beacon_minimal_jump + call s:Highlight_position(v:false) + endif endif let s:prev_cursor = l:cur + endfunction function! s:Beacon_toggle() abort