Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ca12008

Browse files
committedMay 7, 2017
Fix #539 - Just set our highlights again when buffers are shown after being hidden
1 parent f672378 commit ca12008

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed
 

‎autoload/ale/highlight.vim

+23-12
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ endfunction
6565

6666
function! ale#highlight#UpdateHighlights() abort
6767
let l:buffer = bufnr('%')
68-
69-
if has_key(s:buffer_restore_map, l:buffer)
70-
call setmatches(s:buffer_restore_map[l:buffer])
71-
endif
72-
7368
let l:has_new_items = has_key(s:buffer_highlights, l:buffer)
7469
let l:loclist = l:has_new_items ? remove(s:buffer_highlights, l:buffer) : []
7570

@@ -80,7 +75,13 @@ function! ale#highlight#UpdateHighlights() abort
8075
" Remove anything with a current match_id
8176
call filter(l:loclist, '!has_key(v:val, ''match_id'')')
8277

83-
if l:has_new_items
78+
" Restore items from the map of hidden items,
79+
" if we don't have some new items to set already.
80+
if empty(l:loclist) && has_key(s:buffer_restore_map, l:buffer)
81+
let l:loclist = s:buffer_restore_map[l:buffer]
82+
endif
83+
84+
if g:ale_enabled
8485
for l:item in l:loclist
8586
let l:col = l:item.col
8687
let l:group = l:item.type ==# 'E' ? 'ALEError' : 'ALEWarning'
@@ -96,12 +97,22 @@ function! ale#highlight#UpdateHighlights() abort
9697
endfunction
9798

9899
function! ale#highlight#BufferHidden(buffer) abort
99-
" Remember all matches, so they can be restored later.
100-
let s:buffer_restore_map[a:buffer] = filter(
101-
\ getmatches(),
102-
\ 'get(v:val, ''group'', '''')[:2] ==# ''ALE'''
103-
\)
104-
call clearmatches()
100+
let l:info = get(g:ale_buffer_info, a:buffer, {'loclist': []})
101+
let l:loclist = deepcopy(l:info.loclist)
102+
103+
" Remember loclist items, so they can be restored later.
104+
if !empty(l:loclist)
105+
" Remove match_ids, as they must be re-calculated when buffers are
106+
" shown again.
107+
for l:item in l:loclist
108+
if has_key(l:item, 'match_id')
109+
call remove(l:item, 'match_id')
110+
endif
111+
endfor
112+
113+
let s:buffer_restore_map[a:buffer] = l:loclist
114+
call clearmatches()
115+
endif
105116
endfunction
106117

107118
augroup ALEHighlightBufferGroup

‎test/test_highlight_placement.vader

+12-4
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ Execute(Highlights set by ALE should be removed when buffer cleanup is done):
9696

9797
Execute(Highlights should be cleared when buffers are hidden):
9898
call ale#engine#InitBufferInfo(bufnr('%'))
99-
call ale#highlight#SetHighlights(bufnr('%'), [
99+
let g:ale_buffer_info[bufnr('%')].loclist = [
100100
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 3, 'col': 2},
101-
\])
101+
\]
102+
call ale#highlight#SetHighlights(
103+
\ bufnr('%'),
104+
\ g:ale_buffer_info[bufnr('%')].loclist
105+
\)
102106

103107
AssertEqual 1, len(getmatches()), 'The highlights weren''t initially set!'
104108

@@ -112,9 +116,13 @@ Execute(Highlights should be cleared when buffers are hidden):
112116

113117
Execute(Only ALE highlights should be restored when buffers are restored):
114118
call ale#engine#InitBufferInfo(bufnr('%'))
115-
call ale#highlight#SetHighlights(bufnr('%'), [
119+
let g:ale_buffer_info[bufnr('%')].loclist = [
116120
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 3, 'col': 2},
117-
\])
121+
\]
122+
call ale#highlight#SetHighlights(
123+
\ bufnr('%'),
124+
\ g:ale_buffer_info[bufnr('%')].loclist
125+
\)
118126

119127
call matchaddpos('SomeOtherGroup', [[1, 1, 1]])
120128

0 commit comments

Comments
 (0)
Please sign in to comment.