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). the topmost line (case 3).
Performance of the newer formatting algorithm should not depend on the height Performance of the newer formatting algorithm should not depend on the height
of the table (*beware*: something still makes table editing speed linear with of the table. The newer algorithm should also be consistent with respect to
respect to its height, perhaps syntax tracking or some uncovered parts of the user editing experience. Indeed, as soon as a table should normally be edited
formatting algorithm). The newer algorithm should also be consistent with row by row from the top to the bottom, dynamic formatting should be both fast
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
(watching only three rows in a table, re-formatting only when the shrunk (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 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 should look formatted on every press on _Tab_ and _Enter_). However, the newer
newer algorithm differs from the older algorithm when starting editing a algorithm differs from the older algorithm when starting editing a mis-aligned
mis-aligned table in an area where mis-aligned rows do not get into the table in an area where mis-aligned rows do not get into the viewport: in this
viewport: in this case the newer algorithm formats the table partly, in the case the newer algorithm will format the table partly (in the rows of the
rows of the viewport, while the older algorithm re-formats the whole table on viewport) until one of the being edited cells grows in length to a value big
every pressing of _Tab_ and _Enter_. In this case the whole table can be enough to trigger the older algorithm and the whole table gets aligned. When
formatted by pressing `gqq` in the Normal mode. 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 endfunction
function! s:get_indent(lnum) function! s:get_indent(lnum, depth)
if !s:is_table(getline(a:lnum)) if !s:is_table(getline(a:lnum))
return return
endif endif
@ -220,6 +220,9 @@ function! s:get_indent(lnum)
break break
endif endif
let lnum -= 1 let lnum -= 1
if a:depth > 0 && lnum < a:lnum - a:depth
break
endif
endwhile endwhile
return indent return indent
@ -272,9 +275,9 @@ function! s:get_rows(lnum, ...)
endfunction endfunction
function! s:get_cell_aligns(lnum) function! s:get_cell_aligns(lnum, depth)
let aligns = {} 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) let found_separator = s:is_separator(row)
if found_separator if found_separator
let cells = vimwiki#tbl#get_cells(row) let cells = vimwiki#tbl#get_cells(row)
@ -353,7 +356,7 @@ function! s:get_aligned_rows(lnum, col1, col2, depth)
endfor endfor
let max_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows) let max_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows)
endif endif
let aligns = s:get_cell_aligns(a:lnum) let aligns = s:get_cell_aligns(a:lnum, a:depth)
let result = [] let result = []
for [lnum, row] in rows for [lnum, row] in rows
if s:is_separator(row) if s:is_separator(row)
@ -496,8 +499,9 @@ endfunction
function! vimwiki#tbl#goto_next_col() function! vimwiki#tbl#goto_next_col()
let curcol = virtcol('.') let curcol = virtcol('.')
let lnum = line('.') let lnum = line('.')
let newcol = s:get_indent(lnum) let depth = 2
let rows = s:get_rows(lnum, 2) let newcol = s:get_indent(lnum, depth)
let rows = s:get_rows(lnum, depth)
let startlnum = rows[0][0] let startlnum = rows[0][0]
let cells = [] let cells = []
for [lnum, row] in rows for [lnum, row] in rows
@ -530,8 +534,9 @@ endfunction
function! vimwiki#tbl#goto_prev_col() function! vimwiki#tbl#goto_prev_col()
let curcol = virtcol('.') let curcol = virtcol('.')
let lnum = line('.') let lnum = line('.')
let newcol = s:get_indent(lnum) let depth = 2
let rows = s:get_rows(lnum, 2) let newcol = s:get_indent(lnum, depth)
let rows = s:get_rows(lnum, depth)
let startlnum = rows[0][0] let startlnum = rows[0][0]
let cells = [] let cells = []
for [lnum, row] in rows for [lnum, row] in rows
@ -637,7 +642,7 @@ function! vimwiki#tbl#format(lnum, ...)
let col2 = 0 let col2 = 0
endif endif
let indent = s:get_indent(a:lnum) let indent = s:get_indent(a:lnum, depth)
if &expandtab if &expandtab
let indentstring = repeat(' ', indent) let indentstring = repeat(' ', indent)
else else