Merge branch 'dev' of https://github.com/lyokha/vimwiki into lyokha-dev
This commit is contained in:
commit
08dcae9630
@ -268,9 +268,10 @@ function! s:get_rows(lnum, ...)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:get_cell_aligns(lnum)
|
function! s:get_cell_aligns(lnum, ...)
|
||||||
let aligns = {}
|
let aligns = {}
|
||||||
for [lnum, row] in s:get_rows(a:lnum)
|
let depth = a:0 > 0 ? a:1 : 0
|
||||||
|
for [lnum, row] in s:get_rows(a:lnum, depth)
|
||||||
if s:is_separator(row)
|
if s:is_separator(row)
|
||||||
let cells = vimwiki#tbl#get_cells(row)
|
let cells = vimwiki#tbl#get_cells(row)
|
||||||
for idx in range(len(cells))
|
for idx in range(len(cells))
|
||||||
@ -296,6 +297,46 @@ function! s:get_cell_aligns(lnum)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! s:get_cell_fast_aligns(rows)
|
||||||
|
let aligns = {}
|
||||||
|
let clen = 0
|
||||||
|
for [lnum, row] in a:rows
|
||||||
|
if s:is_separator(row)
|
||||||
|
return s:get_cell_aligns(lnum, 1)
|
||||||
|
endif
|
||||||
|
let cells = vimwiki#tbl#get_cells(row, 1)
|
||||||
|
let clen = len(cells)
|
||||||
|
for idx in range(clen)
|
||||||
|
let cell = cells[idx]
|
||||||
|
if !has_key(aligns, idx)
|
||||||
|
let cs = matchlist(cell, '^\(\s*\)[^[:space:]].\{-}\(\s*\)$')
|
||||||
|
if !empty(cs)
|
||||||
|
let lstart = len(cs[1])
|
||||||
|
let lend = len(cs[2])
|
||||||
|
if lstart > 0 || lend > 0
|
||||||
|
if lstart > 0 && lend > 0
|
||||||
|
let aligns[idx] = 'center'
|
||||||
|
else
|
||||||
|
if lend > 0
|
||||||
|
let aligns[idx] = 'left'
|
||||||
|
elseif lstart > 0
|
||||||
|
let aligns[idx] = 'right'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
for idx in range(clen)
|
||||||
|
if !has_key(aligns, idx)
|
||||||
|
return {}
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return aligns
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:get_cell_max_lens(lnum, ...)
|
function! s:get_cell_max_lens(lnum, ...)
|
||||||
let max_lens = {}
|
let max_lens = {}
|
||||||
let rows = a:0 > 2 ? a:3 : s:get_rows(a:lnum)
|
let rows = a:0 > 2 ? a:3 : s:get_rows(a:lnum)
|
||||||
@ -319,6 +360,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:get_aligned_rows(lnum, col1, col2, depth)
|
function! s:get_aligned_rows(lnum, col1, col2, depth)
|
||||||
let rows = []
|
let rows = []
|
||||||
|
let aligns = {}
|
||||||
let startlnum = 0
|
let startlnum = 0
|
||||||
let cells = []
|
let cells = []
|
||||||
let max_lens = {}
|
let max_lens = {}
|
||||||
@ -349,6 +391,7 @@ function! s:get_aligned_rows(lnum, col1, col2, depth)
|
|||||||
endif
|
endif
|
||||||
let fst_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows[0:0])
|
let fst_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows[0:0])
|
||||||
let check_all = max_lens != fst_lens
|
let check_all = max_lens != fst_lens
|
||||||
|
let aligns = s:get_cell_fast_aligns(rows[0:-2])
|
||||||
let rows[-1][1] = line
|
let rows[-1][1] = line
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@ -367,7 +410,9 @@ function! s:get_aligned_rows(lnum, col1, col2, depth)
|
|||||||
let max_lens[last_index] = 1
|
let max_lens[last_index] = 1
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let aligns = s:get_cell_aligns(a:lnum)
|
if empty(aligns)
|
||||||
|
let aligns = s:get_cell_aligns(a:lnum)
|
||||||
|
endif
|
||||||
let result = []
|
let result = []
|
||||||
for [lnum, row] in rows
|
for [lnum, row] in rows
|
||||||
if s:is_separator(row)
|
if s:is_separator(row)
|
||||||
|
Loading…
Reference in New Issue
Block a user