vim:au: Fix flickering of selection highlights
Defer the clearing of the old highlight as well. This means that the old highlight will remain a bit longer but prevents the highlight from flickering because of the continuous `matchdelete`.
This commit is contained in:
@@ -102,8 +102,10 @@ function! s:highlight_selection()
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Clear previous highlight and kill the possibly already running timer
|
" Kill the possibly already running timer
|
||||||
call s:clear_highlights(s:CLEAR_HIGHS_VISUAL)
|
if exists('w:selection_timer_id')
|
||||||
|
call timer_stop(w:selection_timer_id)
|
||||||
|
endif
|
||||||
|
|
||||||
" Delay the highlight by 100ms so that not every selection is highlighted
|
" Delay the highlight by 100ms so that not every selection is highlighted
|
||||||
" while moving the cursor fast. (This kind of simulates a CursorHold
|
" while moving the cursor fast. (This kind of simulates a CursorHold
|
||||||
@@ -128,21 +130,28 @@ function! s:_highlight_selection(timer)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let w:visual_match_ids = []
|
if !exists('w:visual_match_ids')
|
||||||
|
let w:visual_match_ids = {}
|
||||||
|
endif
|
||||||
|
|
||||||
" Add match to all windows containing the current buffer
|
" Add match to all windows containing the current buffer
|
||||||
" NOTE: \%V\@! prevents the pattern from matching the current selection. As
|
" NOTE: This does not delete the matches for windows that do not exist
|
||||||
" it is highlighted already this would be superfluous and inefficient.
|
" anymore, but I don't think that this is an issue and
|
||||||
|
" clear_highlights deletes them later on mode change.
|
||||||
for l:win in win_findbuf(bufnr())
|
for l:win in win_findbuf(bufnr())
|
||||||
let w:visual_match_ids += [[
|
if exists("w:visual_match_ids[l:win]")
|
||||||
|
call matchdelete(w:visual_match_ids[l:win], l:win)
|
||||||
|
endif
|
||||||
|
" NOTE: \%V\@! prevents the pattern from matching the current selection.
|
||||||
|
" As it is highlighted already this would be superfluous and
|
||||||
|
" inefficient.
|
||||||
|
let w:visual_match_ids[l:win] =
|
||||||
\ matchadd(
|
\ matchadd(
|
||||||
\ 'CursorColumn',
|
\ 'CursorColumn',
|
||||||
\ '\V\%V\@!' . substitute(escape(@", '\'), '\n', '\\n', 'g'),
|
\ '\V\%V\@!' . substitute(escape(@", '\'), '\n', '\\n', 'g'),
|
||||||
\ -1,
|
\ -1,
|
||||||
\ -1,
|
\ -1,
|
||||||
\ {'window': l:win}),
|
\ {'window': l:win})
|
||||||
\ l:win
|
|
||||||
\ ]]
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call setreg('"', l:old_reg, l:old_regtype)
|
call setreg('"', l:old_reg, l:old_regtype)
|
||||||
@@ -163,9 +172,7 @@ function! s:clear_highlights(what = s:CLEAR_HIGHS_ALL)
|
|||||||
endif
|
endif
|
||||||
if and(a:what, s:CLEAR_HIGHS_VISUAL)
|
if and(a:what, s:CLEAR_HIGHS_VISUAL)
|
||||||
if exists('w:visual_match_ids')
|
if exists('w:visual_match_ids')
|
||||||
for l:pairs in w:visual_match_ids
|
for [l:win, l:id] in items(w:visual_match_ids)
|
||||||
let l:id = l:pairs[0]
|
|
||||||
let l:win = l:pairs[1]
|
|
||||||
call matchdelete(l:id, l:win)
|
call matchdelete(l:id, l:win)
|
||||||
endfor
|
endfor
|
||||||
unlet w:visual_match_ids
|
unlet w:visual_match_ids
|
||||||
|
|||||||
Reference in New Issue
Block a user