summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 12:47:32 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 12:47:32 +0200
commit36fa529fae92038daaddc7c88ec824cc71c1ffef (patch)
treef3d9288e026b6d1f5c59821c3451d4c15a1dd4fe
parent6c3009c5041a2e661504825f68b0a3675562a647 (diff)
Restore feedback before primary movement
-rw-r--r--lua/clever_f/feedback_service.lua21
-rw-r--r--tests/run.lua44
2 files changed, 60 insertions, 5 deletions
diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua
index 4d19e6d..b15d1c5 100644
--- a/lua/clever_f/feedback_service.lua
+++ b/lua/clever_f/feedback_service.lua
@@ -575,12 +575,11 @@ local function register_finalizers(service, record)
return owned
end
-function FeedbackService:request_persistent(specification)
- local request = self:build_persistent(specification)
+local function materialize_persistent(service, request)
if request.window == nil then
- fail("persistent feedback window must identify its host window", 2)
+ fail("persistent feedback window must identify its host window", 3)
end
- local record = service_records[self]
+ local record = service_records[service]
remove_target_overlays(record, request.window)
request.identity = record.host:create_highlight({
group = "CleverFChar",
@@ -599,12 +598,24 @@ function FeedbackService:request_persistent(specification)
request.window,
request.anchor.line
)
- request.finalizers = register_finalizers(self, record)
+ request.finalizers = register_finalizers(service, record)
local requests = record.persistent_requests
requests[#requests + 1] = request
return request
end
+function FeedbackService:request_persistent(specification)
+ return materialize_persistent(self, self:build_persistent(specification))
+end
+
+function FeedbackService:restore_primary(specification)
+ local restoration = self:build_primary_restoration(specification)
+ if restoration == nil then
+ return nil
+ end
+ return materialize_persistent(self, restoration)
+end
+
function FeedbackService:persistent_requests()
local result = {}
for index, request in ipairs(service_records[self].persistent_requests) do
diff --git a/tests/run.lua b/tests/run.lua
index d66e2c5..2d343b6 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -6791,6 +6791,50 @@ test("Primary restoration combines action target with stored motion policy", fun
)
end)
+test("Primary repetition restores feedback before movement", function()
+ local state, transitions = fresh_sequence_state()
+ local host = MemoryHost.new({
+ buffer_lines = { "aba" },
+ cursor = { line = 1, byte_column = 1 },
+ configuration = { mark_char = true },
+ emit_movement_events = false,
+ })
+ local feedback = feedback_service.new({
+ host = host,
+ transitions = transitions,
+ })
+ local action_target = target_plan.build(target("a"), matching_policy())
+ local action_motion = motion_plan.build(action_target, "f")
+ host:clear_operations()
+
+ local restored = feedback:restore_primary({
+ context = "n",
+ anchor = domain.Position.new(1, 1),
+ target_plan = action_target,
+ motion_plan = action_motion,
+ stored_descriptor = "f",
+ endpoint_policy = domain.EndpointPolicy.REGULAR,
+ window = "window-1",
+ })
+ host:apply_cursor(domain.Position.new(1, 3), {
+ descriptor = domain.Descriptor.FIND_FORWARD,
+ origin = domain.Position.new(1, 1),
+ })
+
+ truthy(restored ~= nil)
+ same(restored.identity, state.target_overlays[1].identity)
+ local create_index
+ local movement_index
+ for index, operation in ipairs(host:operations()) do
+ if operation.operation == "create_highlight" then
+ create_index = index
+ elseif operation.operation == "apply_cursor" then
+ movement_index = index
+ end
+ end
+ truthy(create_index < movement_index)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then