From ae3db7a079d6c9cb8b43a7276c1695fabdab9509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D1=91=D1=85=D0=B0?= Date: Thu, 4 Apr 2019 09:16:05 +0300 Subject: [PATCH] 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. --- autoload/vimwiki/tbl.vim | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/autoload/vimwiki/tbl.vim b/autoload/vimwiki/tbl.vim index 5a8a429..9a7fc85 100644 --- a/autoload/vimwiki/tbl.vim +++ b/autoload/vimwiki/tbl.vim @@ -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