From 70a3f231cf4d8bf76c3c73584502d6a3977167b1 Mon Sep 17 00:00:00 2001 From: Jackson Moore Date: Fri, 4 Sep 2026 12:40:08 +0200 Subject: Cancel finalized highlight timer --- lua/clever_f/feedback_service.lua | 9 +++++++++ tests/run.lua | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua index c5c9fc8..6972d70 100644 --- a/lua/clever_f/feedback_service.lua +++ b/lua/clever_f/feedback_service.lua @@ -115,6 +115,7 @@ local function require_host(host) or type(host.read_window) ~= "function" or type(host.register_events) ~= "function" or type(host.remove_event_registration) ~= "function" + or type(host.stop_timer) ~= "function" or type(host.supports_cursor_presentation) ~= "function" or type(host.suppress_cursor_presentation) ~= "function" or type(host.restore_cursor_presentation) ~= "function" @@ -499,11 +500,19 @@ local function release_finalizers(record, resources) end end +local function release_highlight_timer(record, identity) + if identity == nil then + return false + end + return record.host:stop_timer(identity) +end + function FeedbackService:full_finalize(window) local record = service_records[self] window = window or record.host:read_window() local cleanup = record.transitions:FullFinalization(window) release_finalizers(record, cleanup.finalizers) + release_highlight_timer(record, cleanup.highlight_timer) release_target_overlays(record, cleanup.target_overlays) record.owned_finalizer = nil return cleanup diff --git a/tests/run.lua b/tests/run.lua index 6244677..034d037 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -6297,6 +6297,31 @@ test("Full finalization removes owned registrations and window overlays", functi same(0, #state.finalizers) end) +test("Full finalization cancels the active highlight timer", function() + local state, transitions = fresh_sequence_state() + local host = MemoryHost.new() + local feedback = feedback_service.new({ + host = host, + transitions = transitions, + }) + local timer = host:start_timer(25, function() end) + transitions:SetHighlightTimer(timer) + + local cleanup = feedback:full_finalize("window-1") + + same(timer, cleanup.highlight_timer) + same(nil, state.highlight_timer) + falsy(host:timers()[timer].active) + local stopped + for _, operation in ipairs(host:operations()) do + if operation.operation == "stop_timer" and operation.identity == timer then + stopped = operation + end + end + truthy(stopped ~= nil) + truthy(stopped.stopped) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then -- cgit v1.2.3