(renderer) invalidate cache on buffer change
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m32s
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m32s
This commit is contained in:
@@ -373,6 +373,10 @@ function Renderer:_expr_map_callback(mode, lhs) -- {{{
|
||||
end -- }}}
|
||||
|
||||
function Renderer:_on_text_changed()
|
||||
-- Reset changedtick, so that the reconciler knows to refresh its cached
|
||||
-- buffer-content before computing the diff:
|
||||
self.changedtick = 0
|
||||
|
||||
--- @type integer, integer
|
||||
local l, c = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
l = l - 1 -- make it actually 0-based
|
||||
@@ -574,13 +578,13 @@ function TreeBuilder:tree() return self.nodes end
|
||||
|
||||
-- Levenshtein utility {{{
|
||||
-- luacheck: ignore
|
||||
--- @alias LevenshteinChange<T> ({ kind: 'add'; item: T; index: number; } | { kind: 'delete'; item: T; index: number; } | { kind: 'change'; from: T; to: T; index: number; })
|
||||
--- @alias u.renderer.LevenshteinChange<T> ({ kind: 'add'; item: T; index: number; } | { kind: 'delete'; item: T; index: number; } | { kind: 'change'; from: T; to: T; index: number; })
|
||||
--- @private
|
||||
--- @generic T
|
||||
--- @param x `T`[]
|
||||
--- @param y T[]
|
||||
--- @param cost? { of_delete?: fun(x: T): number; of_add?: fun(x: T): number; of_change?: fun(x: T, y: T): number; }
|
||||
--- @return LevenshteinChange<T>[] The changes, from last (greatest index) to first (smallest index).
|
||||
--- @return u.renderer.LevenshteinChange<T>[] The changes, from last (greatest index) to first (smallest index).
|
||||
function H.levenshtein(x, y, cost)
|
||||
-- At the moment, this whole `cost` plumbing is not used. Deletes have the
|
||||
-- same cost as Adds or Changes. I can imagine a future, however, where
|
||||
@@ -631,7 +635,7 @@ function H.levenshtein(x, y, cost)
|
||||
-- Backtrack to find the changes
|
||||
local i = m
|
||||
local j = n
|
||||
--- @type LevenshteinChange[]
|
||||
--- @type u.renderer.LevenshteinChange[]
|
||||
local changes = {}
|
||||
|
||||
while i > 0 or j > 0 do
|
||||
@@ -648,7 +652,7 @@ function H.levenshtein(x, y, cost)
|
||||
if is_first_min(cost_of_change, cost_of_add, cost_of_delete) then
|
||||
-- potential change
|
||||
if x[i] ~= y[j] then
|
||||
--- @type LevenshteinChange
|
||||
--- @type u.renderer.LevenshteinChange
|
||||
local change = { kind = 'change', from = x[i], index = i, to = y[j] }
|
||||
table.insert(changes, change)
|
||||
end
|
||||
@@ -656,13 +660,13 @@ function H.levenshtein(x, y, cost)
|
||||
j = j - 1
|
||||
elseif is_first_min(cost_of_add, cost_of_change, cost_of_delete) then
|
||||
-- addition
|
||||
--- @type LevenshteinChange
|
||||
--- @type u.renderer.LevenshteinChange
|
||||
local change = { kind = 'add', item = y[j], index = i + 1 }
|
||||
table.insert(changes, change)
|
||||
j = j - 1
|
||||
elseif is_first_min(cost_of_delete, cost_of_change, cost_of_add) then
|
||||
-- deletion
|
||||
--- @type LevenshteinChange
|
||||
--- @type u.renderer.LevenshteinChange
|
||||
local change = { kind = 'delete', item = x[i], index = i }
|
||||
table.insert(changes, change)
|
||||
i = i - 1
|
||||
|
||||
Reference in New Issue
Block a user