add example/form.lua
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m24s
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m24s
This commit is contained in:
@@ -5,7 +5,7 @@ local H = {}
|
||||
|
||||
--- @alias u.renderer.TagEventHandler fun(tag: u.renderer.Tag, mode: string, lhs: string): string
|
||||
|
||||
--- @alias u.renderer.TagAttributes { [string]?: unknown; imap?: table<string, u.renderer.TagEventHandler>; nmap?: table<string, u.renderer.TagEventHandler>; vmap?: table<string, u.renderer.TagEventHandler>; xmap?: table<string, u.renderer.TagEventHandler>; omap?: table<string, u.renderer.TagEventHandler> }
|
||||
--- @alias u.renderer.TagAttributes { [string]?: unknown; imap?: table<string, u.renderer.TagEventHandler>; nmap?: table<string, u.renderer.TagEventHandler>; vmap?: table<string, u.renderer.TagEventHandler>; xmap?: table<string, u.renderer.TagEventHandler>; omap?: table<string, u.renderer.TagEventHandler>, on_change?: fun(text: string): unknown }
|
||||
|
||||
--- @class u.renderer.Tag
|
||||
--- @field kind 'tag'
|
||||
@@ -296,10 +296,15 @@ function Renderer:_reconcile() -- {{{
|
||||
|
||||
--
|
||||
-- Step 2: reconcile extmarks:
|
||||
-- You may be tempted to try to keep track of which extmarks are needed, and
|
||||
-- only delete those that are not needed. However, each time a tree is
|
||||
-- rendered, brand new extmarks are created. For simplicity, it is better to
|
||||
-- just delete all extmarks, and recreate them.
|
||||
--
|
||||
|
||||
-- Clear current extmarks:
|
||||
vim.api.nvim_buf_clear_namespace(self.bufnr, self.ns, 0, -1)
|
||||
|
||||
-- Set current extmarks:
|
||||
for _, extmark in ipairs(self.curr.extmarks) do
|
||||
extmark.id = vim.api.nvim_buf_set_extmark(
|
||||
@@ -361,10 +366,9 @@ function Renderer:_on_text_changed()
|
||||
for _, pos_info in ipairs(pos_infos) do
|
||||
local extmark_inf = pos_info.extmark
|
||||
local tag = pos_info.tag
|
||||
if tag.attributes.signal and getmetatable(tag.attributes.signal) == Signal then
|
||||
--- @type u.Signal
|
||||
local signal = tag.attributes.signal
|
||||
|
||||
local on_change = tag.attributes.on_change
|
||||
if on_change and type(on_change) == 'function' then
|
||||
local extmark =
|
||||
vim.api.nvim_buf_get_extmark_by_id(self.bufnr, self.ns, extmark_inf.id, { details = true })
|
||||
|
||||
@@ -381,7 +385,7 @@ function Renderer:_on_text_changed()
|
||||
{ type = 'v' }
|
||||
)
|
||||
local text = table.concat(lines, '\n')
|
||||
if text ~= signal:get() then signal:schedule_set(text) end
|
||||
on_change(text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user