Skip to content

Commit c9263d9

Browse files
committed
fix highlighting separator when component group is skipped due to expanding components (close itchyny#289, itchyny#290)
1 parent 166f179 commit c9263d9

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

autoload/lightline.vim

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Filename: autoload/lightline.vim
33
" Author: itchyny
44
" License: MIT License
5-
" Last Change: 2018/06/22 08:50:00.
5+
" Last Change: 2018/09/16 23:00:00.
66
" =============================================================================
77

88
let s:save_cpo = &cpo
@@ -343,9 +343,9 @@ function! s:convert(name, index) abort
343343
let type = get(s:lightline.component_type, a:name, a:index)
344344
let is_raw = get(s:lightline.component_raw, a:name) || type ==# 'raw'
345345
return filter(s:map(s:evaluate_expand(s:lightline.component_expand[a:name]),
346-
\ '[v:val, 1 + ' . is_raw . ', v:key == 1 && ' . (type !=# 'raw') . ' ? "' . type . '" : "' . a:index . '"]'), 'v:val[0] != []')
346+
\ '[v:val, 1 + ' . is_raw . ', v:key == 1 && ' . (type !=# 'raw') . ' ? "' . type . '" : "' . a:index . '", "' . a:index . '"]'), 'v:val[0] != []')
347347
else
348-
return [[[a:name], 0, a:index]]
348+
return [[[a:name], 0, a:index, a:index]]
349349
endif
350350
endfunction
351351

@@ -375,16 +375,23 @@ function! s:expand(components) abort
375375
let components = []
376376
let expanded = []
377377
let indices = []
378+
let prevtype = ''
378379
let previndex = -1
379380
let xs = s:flatten_twice(s:map(deepcopy(a:components), 'map(v:val, "s:convert(v:val, ''" . v:key . "'')")'))
380-
for [component, expand, index] in xs
381-
if previndex != index
382-
call add(indices, index)
381+
for [component, expand, type, index] in xs
382+
if prevtype !=# type
383+
for i in range(previndex + 1, max([previndex, index - 1]))
384+
call add(indices, string(i))
385+
call add(components, [])
386+
call add(expanded, [])
387+
endfor
388+
call add(indices, type)
383389
call add(components, [])
384390
call add(expanded, [])
385391
endif
386392
call extend(components[-1], component)
387393
call extend(expanded[-1], repeat([expand], len(component)))
394+
let prevtype = type
388395
let previndex = index
389396
endfor
390397
call add(indices, string(len(a:components)))

test/expand.vim

+10-10
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function! s:suite.custom_void_string()
156156
let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
157157
call lightline#init()
158158
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
159-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
159+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
160160
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
161161
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
162162
delfunction Custom
@@ -169,7 +169,7 @@ function! s:suite.custom_type_void_string()
169169
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
170170
call lightline#init()
171171
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
172-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
172+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
173173
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
174174
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
175175
delfunction Custom
@@ -208,7 +208,7 @@ function! s:suite.custom_void_string_array()
208208
let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
209209
call lightline#init()
210210
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
211-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
211+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
212212
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
213213
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
214214
delfunction Custom
@@ -221,7 +221,7 @@ function! s:suite.custom_type_void_string_array()
221221
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
222222
call lightline#init()
223223
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
224-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
224+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
225225
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
226226
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
227227
delfunction Custom
@@ -234,7 +234,7 @@ function! s:suite.custom_void_string_array_2()
234234
let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
235235
call lightline#init()
236236
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
237-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
237+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
238238
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
239239
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
240240
delfunction Custom
@@ -247,7 +247,7 @@ function! s:suite.custom_type_void_string_array_2()
247247
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
248248
call lightline#init()
249249
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
250-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
250+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
251251
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
252252
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
253253
delfunction Custom
@@ -469,7 +469,7 @@ function! s:suite.custom_error()
469469
let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
470470
call lightline#init()
471471
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
472-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
472+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
473473
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
474474
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
475475
delfunction Custom
@@ -483,7 +483,7 @@ function! s:suite.custom_type_error()
483483
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
484484
call lightline#init()
485485
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
486-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
486+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
487487
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
488488
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
489489
delfunction Custom
@@ -493,7 +493,7 @@ function! s:suite.notfound()
493493
let g:lightline = { 'component_expand': { 'custom': 'NotFound' } }
494494
call lightline#init()
495495
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
496-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
496+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
497497
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
498498
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
499499
endfunction
@@ -502,7 +502,7 @@ function! s:suite.custom_type_notfound()
502502
let g:lightline = { 'component_expand': { 'custom': 'NotFound' }, 'component_type': { 'custom': 'custom' } }
503503
call lightline#init()
504504
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
505-
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']])
505+
\ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
506506
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
507507
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
508508
endfunction

0 commit comments

Comments
 (0)