summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/feedback_service.lua29
-rw-r--r--tests/run.lua35
2 files changed, 64 insertions, 0 deletions
diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua
index 98f51aa..d84fcb3 100644
--- a/lua/clever_f/feedback_service.lua
+++ b/lua/clever_f/feedback_service.lua
@@ -119,6 +119,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.start_timer) ~= "function"
or type(host.stop_timer) ~= "function"
or type(host.supports_timers) ~= "function"
or type(host.supports_cursor_presentation) ~= "function"
@@ -140,6 +141,8 @@ local function require_transitions(transitions, state)
or type(transitions.AddFinalizer) ~= "function"
or type(transitions.RemoveFinalizer) ~= "function"
or type(transitions.FullFinalization) ~= "function"
+ or type(transitions.SetHighlightTimer) ~= "function"
+ or type(transitions.ClearHighlightTimer) ~= "function"
then
fail("FeedbackService transitions must manage overlay resources", 3)
end
@@ -702,6 +705,32 @@ function FeedbackService:highlight_timer_delay()
return delay
end
+function FeedbackService:cancel_highlight_timer()
+ local record = service_records[self]
+ local identity = record.transitions:ClearHighlightTimer()
+ release_highlight_timer(record, identity)
+ return identity
+end
+
+function FeedbackService:handle_highlight_timer()
+ return false
+end
+
+function FeedbackService:start_highlight_timer()
+ local record = service_records[self]
+ local delay = self:highlight_timer_delay()
+ if delay == nil then
+ return nil
+ end
+ self:cancel_highlight_timer()
+ local identity
+ identity = record.host:start_timer(delay, function(callback_identity)
+ self:handle_highlight_timer(callback_identity or identity)
+ end)
+ record.transitions:SetHighlightTimer(identity)
+ return identity
+end
+
function FeedbackService:evaluate_feature_links()
local record = service_records[self]
local rules = record.policy:evaluate_highlight_links()
diff --git a/tests/run.lua b/tests/run.lua
index aa01e7f..76d6f50 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -6589,6 +6589,41 @@ test("Highlight timeout requires marks delay and timer support", function()
end
end)
+test("A new primary timer stops the prior timer first", function()
+ local _, transitions = fresh_sequence_state()
+ local host = MemoryHost.new({
+ configuration = {
+ mark_char = true,
+ highlight_timeout_ms = 25,
+ },
+ })
+ local feedback = feedback_service.new({
+ host = host,
+ transitions = transitions,
+ })
+ local first = feedback:start_highlight_timer()
+ host:clear_operations()
+ local second = feedback:start_highlight_timer()
+ local stop_index
+ local start_index
+ for index, operation in ipairs(host:operations()) do
+ if operation.operation == "stop_timer" and operation.identity == first then
+ stop_index = index
+ elseif operation.operation == "start_timer"
+ and operation.identity == second
+ then
+ start_index = index
+ end
+ end
+
+ truthy(first ~= second)
+ truthy(stop_index ~= nil)
+ truthy(start_index ~= nil)
+ truthy(stop_index < start_index)
+ falsy(host:timers()[first].active)
+ truthy(host:timers()[second].active)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then