summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-03 23:27:42 +0100
committerw0rp <devw0rp@gmail.com>2017-05-03 23:28:57 +0100
commit0aed51565eae5f03dc400409ef73697333bb4f16 (patch)
tree002135e857a8f1b36a3572aa778a7a6fc2a9ca49
parent858c1c47ae623876453760d0a0cbab8bb72e6fef (diff)
downloadale-0aed51565eae5f03dc400409ef73697333bb4f16.zip
Fix #528 remove and restore highlights when buffers are hidden and shown
-rw-r--r--autoload/ale/highlight.vim17
-rw-r--r--test/test_highlight_placement.vader16
2 files changed, 33 insertions, 0 deletions
diff --git a/autoload/ale/highlight.vim b/autoload/ale/highlight.vim
index 8ff5120f..15b77d3d 100644
--- a/autoload/ale/highlight.vim
+++ b/autoload/ale/highlight.vim
@@ -15,11 +15,16 @@ endif
" wait until the buffer is entered again to show the highlights, unless
" the buffer is in focus when linting completes.
let s:buffer_highlights = {}
+let s:buffer_restore_map = {}
function! ale#highlight#UnqueueHighlights(buffer) abort
if has_key(s:buffer_highlights, a:buffer)
call remove(s:buffer_highlights, a:buffer)
endif
+
+ if has_key(s:buffer_restore_map, a:buffer)
+ call remove(s:buffer_restore_map, a:buffer)
+ endif
endfunction
function! s:GetALEMatches() abort
@@ -60,6 +65,11 @@ endfunction
function! ale#highlight#UpdateHighlights() abort
let l:buffer = bufnr('%')
+
+ if has_key(s:buffer_restore_map, l:buffer)
+ call setmatches(s:buffer_restore_map[l:buffer])
+ endif
+
let l:has_new_items = has_key(s:buffer_highlights, l:buffer)
let l:loclist = l:has_new_items ? remove(s:buffer_highlights, l:buffer) : []
@@ -85,9 +95,16 @@ function! ale#highlight#UpdateHighlights() abort
endif
endfunction
+function! ale#highlight#BufferHidden(buffer) abort
+ " Remember all matches, so they can be restored later.
+ let s:buffer_restore_map[a:buffer] = getmatches()
+ call clearmatches()
+endfunction
+
augroup ALEHighlightBufferGroup
autocmd!
autocmd BufEnter * call ale#highlight#UpdateHighlights()
+ autocmd BufHidden * call ale#highlight#BufferHidden(expand('<abuf>'))
augroup END
function! ale#highlight#SetHighlights(buffer, loclist) abort
diff --git a/test/test_highlight_placement.vader b/test/test_highlight_placement.vader
index bca7bfda..14c16328 100644
--- a/test/test_highlight_placement.vader
+++ b/test/test_highlight_placement.vader
@@ -91,3 +91,19 @@ Execute(Highlights set by ALE should be removed when buffer cleanup is done):
call ale#cleanup#Buffer(bufnr('%'))
AssertEqual [], getmatches()
+
+Execute(Highlights should be cleared when buffers are hidden):
+ call ale#engine#InitBufferInfo(bufnr('%'))
+ call ale#highlight#SetHighlights(bufnr('%'), [
+ \ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 3, 'col': 2},
+ \])
+
+ AssertEqual 1, len(getmatches()), 'The highlights weren''t initially set!'
+
+ call ale#highlight#BufferHidden(bufnr('%'))
+
+ AssertEqual 0, len(getmatches()), 'The highlights weren''t cleared!'
+
+ call ale#highlight#UpdateHighlights()
+
+ AssertEqual 1, len(getmatches()), 'The highlights weren''t set again!'