fix highlighting separator when component group is skipped due to expanding components (close #289, #290)

This commit is contained in:
itchyny
2018-09-16 23:12:53 +09:00
parent 166f179cf8
commit c9263d945e
2 changed files with 23 additions and 16 deletions

View File

@@ -2,7 +2,7 @@
" Filename: autoload/lightline.vim " Filename: autoload/lightline.vim
" Author: itchyny " Author: itchyny
" License: MIT License " License: MIT License
" Last Change: 2018/06/22 08:50:00. " Last Change: 2018/09/16 23:00:00.
" ============================================================================= " =============================================================================
let s:save_cpo = &cpo let s:save_cpo = &cpo
@@ -343,9 +343,9 @@ function! s:convert(name, index) abort
let type = get(s:lightline.component_type, a:name, a:index) let type = get(s:lightline.component_type, a:name, a:index)
let is_raw = get(s:lightline.component_raw, a:name) || type ==# 'raw' let is_raw = get(s:lightline.component_raw, a:name) || type ==# 'raw'
return filter(s:map(s:evaluate_expand(s:lightline.component_expand[a:name]), return filter(s:map(s:evaluate_expand(s:lightline.component_expand[a:name]),
\ '[v:val, 1 + ' . is_raw . ', v:key == 1 && ' . (type !=# 'raw') . ' ? "' . type . '" : "' . a:index . '"]'), 'v:val[0] != []') \ '[v:val, 1 + ' . is_raw . ', v:key == 1 && ' . (type !=# 'raw') . ' ? "' . type . '" : "' . a:index . '", "' . a:index . '"]'), 'v:val[0] != []')
else else
return [[[a:name], 0, a:index]] return [[[a:name], 0, a:index, a:index]]
endif endif
endfunction endfunction
@@ -375,16 +375,23 @@ function! s:expand(components) abort
let components = [] let components = []
let expanded = [] let expanded = []
let indices = [] let indices = []
let prevtype = ''
let previndex = -1 let previndex = -1
let xs = s:flatten_twice(s:map(deepcopy(a:components), 'map(v:val, "s:convert(v:val, ''" . v:key . "'')")')) let xs = s:flatten_twice(s:map(deepcopy(a:components), 'map(v:val, "s:convert(v:val, ''" . v:key . "'')")'))
for [component, expand, index] in xs for [component, expand, type, index] in xs
if previndex != index if prevtype !=# type
call add(indices, index) for i in range(previndex + 1, max([previndex, index - 1]))
call add(indices, string(i))
call add(components, [])
call add(expanded, [])
endfor
call add(indices, type)
call add(components, []) call add(components, [])
call add(expanded, []) call add(expanded, [])
endif endif
call extend(components[-1], component) call extend(components[-1], component)
call extend(expanded[-1], repeat([expand], len(component))) call extend(expanded[-1], repeat([expand], len(component)))
let prevtype = type
let previndex = index let previndex = index
endfor endfor
call add(indices, string(len(a:components))) call add(indices, string(len(a:components)))

View File

@@ -156,7 +156,7 @@ function! s:suite.custom_void_string()
let g:lightline = { 'component_expand': { 'custom': 'Custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -169,7 +169,7 @@ function! s:suite.custom_type_void_string()
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -208,7 +208,7 @@ function! s:suite.custom_void_string_array()
let g:lightline = { 'component_expand': { 'custom': 'Custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -221,7 +221,7 @@ function! s:suite.custom_type_void_string_array()
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -234,7 +234,7 @@ function! s:suite.custom_void_string_array_2()
let g:lightline = { 'component_expand': { 'custom': 'Custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -247,7 +247,7 @@ function! s:suite.custom_type_void_string_array_2()
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -469,7 +469,7 @@ function! s:suite.custom_error()
let g:lightline = { 'component_expand': { 'custom': 'Custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -483,7 +483,7 @@ function! s:suite.custom_type_error()
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } } let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
delfunction Custom delfunction Custom
@@ -493,7 +493,7 @@ function! s:suite.notfound()
let g:lightline = { 'component_expand': { 'custom': 'NotFound' } } let g:lightline = { 'component_expand': { 'custom': 'NotFound' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
endfunction endfunction
@@ -502,7 +502,7 @@ function! s:suite.custom_type_notfound()
let g:lightline = { 'component_expand': { 'custom': 'NotFound' }, 'component_type': { 'custom': 'custom' } } let g:lightline = { 'component_expand': { 'custom': 'NotFound' }, 'component_type': { 'custom': 'custom' } }
call lightline#init() call lightline#init()
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]), call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
\ [[['readonly', 'filename'], ['modified']], [[0, 0], [0]], ['0', '2', '3']]) \ [[['readonly', 'filename'], [], ['modified']], [[0, 0], [], [0]], ['0', '1', '2', '3']])
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]), call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
\ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']]) \ [[['readonly', 'filename', 'modified']], [[0, 0, 0]], ['0', '1']])
endfunction endfunction