the cause of the linear slowing down was fixed

This commit is contained in:
lyokha 2019-03-18 17:49:13 +03:00
parent 1f4fb8ca58
commit ad6a3bceb6
2 changed files with 25 additions and 21 deletions

View File

@ -171,18 +171,17 @@ and the shrunk current line, then the two lowest lines get aligned according to
the topmost line (case 3).
Performance of the newer formatting algorithm should not depend on the height
of the table (*beware*: something still makes table editing speed linear with
respect to its height, perhaps syntax tracking or some uncovered parts of the
formatting algorithm). The newer algorithm should also be consistent with
respect to user editing experience. Indeed, as soon as a table should normally
be edited linearly, row by row, dynamic formatting should be both fast
of the table. The newer algorithm should also be consistent with respect to
user editing experience. Indeed, as soon as a table should normally be edited
row by row from the top to the bottom, dynamic formatting should be both fast
(watching only three rows in a table, re-formatting only when the shrunk
current row gets longer than any of the two rows above) and eager (a table
should look formatted on every pressing on _Tab_ and _Enter_). However, the
newer algorithm differs from the older algorithm when starting editing a
mis-aligned table in an area where mis-aligned rows do not get into the
viewport: in this case the newer algorithm formats the table partly, in the
rows of the viewport, while the older algorithm re-formats the whole table on
every pressing of _Tab_ and _Enter_. In this case the whole table can be
formatted by pressing `gqq` in the Normal mode.
should look formatted on every press on _Tab_ and _Enter_). However, the newer
algorithm differs from the older algorithm when starting editing a mis-aligned
table in an area where mis-aligned rows do not get into the viewport: in this
case the newer algorithm will format the table partly (in the rows of the
viewport) until one of the being edited cells grows in length to a value big
enough to trigger the older algorithm and the whole table gets aligned. When
partial formatting is not desirable, the whole table can be formatted by
pressing `gqq` in the Normal mode.

View File

@ -205,7 +205,7 @@ function! s:col_count(lnum)
endfunction
function! s:get_indent(lnum)
function! s:get_indent(lnum, depth)
if !s:is_table(getline(a:lnum))
return
endif
@ -220,6 +220,9 @@ function! s:get_indent(lnum)
break
endif
let lnum -= 1
if a:depth > 0 && lnum < a:lnum - a:depth
break
endif
endwhile
return indent
@ -272,9 +275,9 @@ function! s:get_rows(lnum, ...)
endfunction
function! s:get_cell_aligns(lnum)
function! s:get_cell_aligns(lnum, depth)
let aligns = {}
for [lnum, row] in s:get_rows(a:lnum)
for [lnum, row] in s:get_rows(a:lnum, a:depth)
let found_separator = s:is_separator(row)
if found_separator
let cells = vimwiki#tbl#get_cells(row)
@ -353,7 +356,7 @@ function! s:get_aligned_rows(lnum, col1, col2, depth)
endfor
let max_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows)
endif
let aligns = s:get_cell_aligns(a:lnum)
let aligns = s:get_cell_aligns(a:lnum, a:depth)
let result = []
for [lnum, row] in rows
if s:is_separator(row)
@ -496,8 +499,9 @@ endfunction
function! vimwiki#tbl#goto_next_col()
let curcol = virtcol('.')
let lnum = line('.')
let newcol = s:get_indent(lnum)
let rows = s:get_rows(lnum, 2)
let depth = 2
let newcol = s:get_indent(lnum, depth)
let rows = s:get_rows(lnum, depth)
let startlnum = rows[0][0]
let cells = []
for [lnum, row] in rows
@ -530,8 +534,9 @@ endfunction
function! vimwiki#tbl#goto_prev_col()
let curcol = virtcol('.')
let lnum = line('.')
let newcol = s:get_indent(lnum)
let rows = s:get_rows(lnum, 2)
let depth = 2
let newcol = s:get_indent(lnum, depth)
let rows = s:get_rows(lnum, depth)
let startlnum = rows[0][0]
let cells = []
for [lnum, row] in rows
@ -637,7 +642,7 @@ function! vimwiki#tbl#format(lnum, ...)
let col2 = 0
endif
let indent = s:get_indent(a:lnum)
let indent = s:get_indent(a:lnum, depth)
if &expandtab
let indentstring = repeat(' ', indent)
else