From 8fefd6c97e9770fbf75c85b7f88c25ecbfd8b3cc Mon Sep 17 00:00:00 2001 From: Lemmy Date: Fri, 24 Jul 2026 22:38:38 -0400 Subject: [PATCH] refactor(todo): use closure callbacks --- todo/panel.luau | 43 ++++++++++++++++--------------------------- todo/plugin.toml | 4 ++-- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/todo/panel.luau b/todo/panel.luau index 8cf7f92..ca55e3f 100644 --- a/todo/panel.luau +++ b/todo/panel.luau @@ -50,17 +50,6 @@ local confirmingClear = false -- header trash pressed, awaiting confirm/cancel local render --- Per-row callbacks need distinct global names; the reconciler dispatches --- callbacks by name only. getfenv() is the script environment lua_getglobal --- reads from, so assigning into it defines the callback the host will find. --- Keyed by the stable id, so a callback stays valid as rows reorder. -local env = getfenv() -local function rowCallback(prefix, id, fn) - local name = prefix .. "_" .. id - env[name] = fn - return name -end - local function tr(key, args) return noctalia.tr(key, args) end @@ -377,9 +366,9 @@ local function taskRow(item) height = 16, radius = 4, fill = COLORS[item.priority], - onClick = rowCallback("todoPrio", id, function() + onClick = function() cyclePriority(id) - end), + end, }) local children = {} if grip ~= nil then @@ -394,23 +383,23 @@ local function taskRow(item) placeholder = tr("placeholder"), focus = true, flexGrow = 1, - onChange = rowCallback("todoText", id, function(value) + onChange = function(value) item.text = value dirty = true idleTicks = 0 - end), - onSubmit = rowCallback("todoSubmit", id, function(value) + end, + onSubmit = function(value) commitEdit(id, value) - end), + end, })) -- ✓ commits the edit, mirroring Enter. table.insert(children, ui.button({ glyph = "check", variant = "primary", tooltip = tr("tip_commit"), - onClick = rowCallback("todoOk", id, function() + onClick = function() commitEdit(id, item.text) - end), + end, })) else -- Static text; clicking it re-opens the editor ("press on the text"). @@ -420,27 +409,27 @@ local function taskRow(item) variant = "ghost", contentAlign = "start", flexGrow = 1, - onClick = rowCallback("todoEdit", id, function() + onClick = function() enterEdit(id) - end), + end, })) -- Done toggle: strikes the text through. table.insert(children, ui.button({ glyph = item.done and "square-check" or "square", variant = "ghost", tooltip = tr(item.done and "tip_undone" or "tip_done"), - onClick = rowCallback("todoDone", id, function() + onClick = function() toggleDone(id) - end), + end, })) -- Explicit edit affordance next to the row. table.insert(children, ui.button({ glyph = "pencil", variant = "ghost", tooltip = tr("tip_edit"), - onClick = rowCallback("todoPencil", id, function() + onClick = function() enterEdit(id) - end), + end, })) end @@ -448,9 +437,9 @@ local function taskRow(item) glyph = "trash", variant = "ghost", tooltip = tr("tip_delete"), - onClick = rowCallback("todoDel", id, function() + onClick = function() deleteItem(id) - end), + end, })) return ui.row({ diff --git a/todo/plugin.toml b/todo/plugin.toml index 56334b9..1e525d0 100644 --- a/todo/plugin.toml +++ b/todo/plugin.toml @@ -8,8 +8,8 @@ id = "nightwatch75/todo" name = "To Do" -version = "0.0.9" -plugin_api = 5 +version = "0.0.10" +plugin_api = 9 author = "nightwatch75" license = "MIT" dependencies = []