Do not format current table line directly in get_rows()
This formatting is needed in the optimized table formatting algorithm for shrinking the current table line to try the best to avoid re-formatting the whole table. However, this breaks cursor motion and may also affect other table related behaviors. The fix is to move this formatting to get_aligned_rows(). Now table rows are not affected by any means, because the current row is only replaced temporarily for the formatting purpose only and gets reverted as soon as the check is finished. Fixes #656.
This commit is contained in:
parent
3c0ae2ff97
commit
ae3db7a079
@ -254,13 +254,6 @@ function! s:get_rows(lnum, ...)
|
||||
while lnum <= line('$')
|
||||
let line = getline(lnum)
|
||||
if s:is_table(line)
|
||||
if lnum == a:lnum && !s:is_separator(line)
|
||||
let cells = vimwiki#tbl#get_cells(line)
|
||||
let clen = len(cells)
|
||||
let max_lens = repeat([0], clen)
|
||||
let aligns = repeat(['left'], clen)
|
||||
let line = s:fmt_row(cells, max_lens, aligns, 0, 0)
|
||||
endif
|
||||
call add(rows, [lnum, line])
|
||||
else
|
||||
break
|
||||
@ -335,6 +328,14 @@ function! s:get_aligned_rows(lnum, col1, col2, depth)
|
||||
let startlnum = rows[0][0]
|
||||
let lrows = len(rows)
|
||||
if lrows == a:depth + 1
|
||||
let line = rows[-1][1]
|
||||
if !s:is_separator(line)
|
||||
let lcells = vimwiki#tbl#get_cells(line)
|
||||
let lclen = len(lcells)
|
||||
let lmax_lens = repeat([0], lclen)
|
||||
let laligns = repeat(['left'], lclen)
|
||||
let rows[-1][1] = s:fmt_row(lcells, lmax_lens, laligns, 0, 0)
|
||||
endif
|
||||
let i = 1
|
||||
for [lnum, row] in rows
|
||||
call add(cells, vimwiki#tbl#get_cells(row, i != lrows - 1))
|
||||
@ -348,6 +349,7 @@ function! s:get_aligned_rows(lnum, col1, col2, depth)
|
||||
endif
|
||||
let fst_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows[0:0])
|
||||
let check_all = max_lens != fst_lens
|
||||
let rows[-1][1] = line
|
||||
endif
|
||||
endif
|
||||
if check_all
|
||||
|
Loading…
Reference in New Issue
Block a user