better extmark inclusivity
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m21s

This commit is contained in:
2025-06-17 23:37:16 -06:00
parent 28714fb51b
commit 103270a241
4 changed files with 52 additions and 17 deletions

View File

@@ -10,9 +10,6 @@ local Renderer = require('u.renderer').Renderer
local h = require('u.renderer').h
local tracker = require 'u.tracker'
-- Utility to trim brackets from strings:
local function trimb(s) return (s:gsub('^%[(.*)%]$', '%1')) end
-- Create a new, temporary, buffer to the side:
vim.cmd.vnew()
vim.bo.buftype = 'nofile'
@@ -21,13 +18,13 @@ vim.bo.buflisted = false
local renderer = Renderer.new()
-- Create two signals:
local s_name = tracker.create_signal '[whoever-you-are]'
local s_age = tracker.create_signal '[ideally-a-number]'
local s_name = tracker.create_signal 'whoever-you-are'
local s_age = tracker.create_signal 'ideally-a-number'
-- We can create derived information from the signals above. Say we want to do
-- some validation on the input for `age`: we can do that with a memo:
local s_age_info = tracker.create_memo(function()
local age_raw = trimb(s_age:get())
local age_raw = s_age:get()
local age_digits = age_raw:match '^%s*(%d+)%s*$'
local age_n = age_digits and tonumber(age_digits) or nil
return {
@@ -59,9 +56,8 @@ tracker.create_effect(function()
on_change = function(text) s_name:set(text) end,
}, name),
},
'\n',
{
'Age: ',
'\nAge: ',
h.Structure({
on_change = function(text) s_age:set(text) end,
}, age),
@@ -72,7 +68,7 @@ tracker.create_effect(function()
-- Show the values of the signals here, too, so that we can see the
-- reactivity in action. If you change the values in the tags above, you
-- can see the changes reflected here immediately.
{ 'Hello, "', trimb(name), '"!' },
{ 'Hello, "', name, '"!' },
--
-- A more complex example: we can do much more complex rendering, based on