summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 12:45:10 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 12:45:10 +0200
commit800ec4fae75b9bfb69b132ddffc28d88c8690a3b (patch)
tree9271569157983d1536b30f40241501b19cbb8347
parentf52894183ed7f8f0d19afc095fe711f35d6847f7 (diff)
Reject stale timer callbacks
-rw-r--r--lua/clever_f/feedback_service.lua7
-rw-r--r--tests/run.lua21
2 files changed, 26 insertions, 2 deletions
diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua
index d84fcb3..edaa39d 100644
--- a/lua/clever_f/feedback_service.lua
+++ b/lua/clever_f/feedback_service.lua
@@ -712,8 +712,11 @@ function FeedbackService:cancel_highlight_timer()
return identity
end
-function FeedbackService:handle_highlight_timer()
- return false
+function FeedbackService:handle_highlight_timer(callback_identity)
+ if callback_identity == nil then
+ fail("highlight timer callback identity must be present", 2)
+ end
+ return callback_identity == service_records[self].state.highlight_timer
end
function FeedbackService:start_highlight_timer()
diff --git a/tests/run.lua b/tests/run.lua
index a511fb0..c3e7009 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -6645,6 +6645,27 @@ test("Each new highlight timer identity is stored in sequence state", function()
same(40, host:timers()[second].delay_ms)
end)
+test("Timer callbacks compare their identity with current state", function()
+ local state, transitions = fresh_sequence_state()
+ local host = MemoryHost.new({
+ configuration = {
+ mark_char = true,
+ highlight_timeout_ms = 10,
+ },
+ })
+ local feedback = feedback_service.new({
+ host = host,
+ transitions = transitions,
+ })
+ local stale = feedback:start_highlight_timer()
+ local current = feedback:start_highlight_timer()
+
+ falsy(feedback:handle_highlight_timer(stale))
+ same(current, state.highlight_timer)
+ truthy(feedback:handle_highlight_timer(current))
+ same(current, state.highlight_timer)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then