summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/feedback_service.lua35
-rw-r--r--tests/run.lua35
2 files changed, 70 insertions, 0 deletions
diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua
index 4262e1b..4d19e6d 100644
--- a/lua/clever_f/feedback_service.lua
+++ b/lua/clever_f/feedback_service.lua
@@ -673,6 +673,41 @@ function FeedbackService:primary_restoration_active(context, window)
return not has_target_overlay(record, window)
end
+function FeedbackService:build_primary_restoration(specification)
+ if type(specification) ~= "table" then
+ fail("primary feedback restoration must be a table", 2)
+ end
+ local window = specification.window
+ or service_records[self].host:read_window()
+ if not self:primary_restoration_active(specification.context, window) then
+ return nil
+ end
+ if not domain.TargetPlan.is(specification.target_plan) then
+ fail("primary feedback restoration requires an action TargetPlan", 2)
+ end
+ local action_motion_plan = specification.motion_plan
+ local search_scope = specification.search_scope
+ or (domain.ResolvedMotionPlan.is(action_motion_plan)
+ and action_motion_plan.search_scope)
+ or domain.SearchScope.BUFFER
+ local motion_plan = domain.ResolvedMotionPlan.new({
+ target_plan = specification.target_plan,
+ descriptor = specification.stored_descriptor,
+ search_scope = search_scope,
+ endpoint_policy = specification.endpoint_policy,
+ })
+ return self:build_persistent({
+ context = specification.context,
+ anchor = specification.anchor,
+ target_plan = specification.target_plan,
+ motion_plan = motion_plan,
+ descriptor = specification.stored_descriptor,
+ endpoint_policy = specification.endpoint_policy,
+ text_view = specification.text_view,
+ window = window,
+ })
+end
+
function FeedbackService:migrate_command(request)
local reason = M.command_migration_reason(request)
local record = service_records[self]
diff --git a/tests/run.lua b/tests/run.lua
index 9793411..d66e2c5 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -6756,6 +6756,41 @@ test("Primary restoration samples marker and context eligibility", function()
truthy(feedback:primary_restoration_active("s", "window-1"))
end)
+test("Primary restoration combines action target with stored motion policy", function()
+ fresh_sequence_state()
+ local host = MemoryHost.new({
+ buffer_lines = { "aA" },
+ configuration = { mark_char = true },
+ })
+ local feedback = feedback_service.new(host)
+ local action_target = target_plan.build(target("a"), {
+ ignore_case = true,
+ smart_case = false,
+ use_migemo = false,
+ chars_match_any_signs = "",
+ })
+ local action_motion = motion_plan.build(action_target, "f")
+ local restoration = feedback:build_primary_restoration({
+ context = "v",
+ anchor = domain.Position.new(1, 1),
+ target_plan = action_target,
+ motion_plan = action_motion,
+ stored_descriptor = "T",
+ endpoint_policy = domain.EndpointPolicy.VISUAL_EXCLUSIVE,
+ window = "window-1",
+ })
+
+ same(action_target, restoration.target_plan)
+ same(action_target, restoration.motion_plan.target_plan)
+ same(domain.Descriptor.TILL_BACKWARD, restoration.descriptor)
+ same(domain.Descriptor.TILL_BACKWARD, restoration.motion_plan.descriptor)
+ same(domain.EndpointPolicy.VISUAL_EXCLUSIVE, restoration.endpoint_policy)
+ same(
+ domain.EndpointPolicy.VISUAL_EXCLUSIVE,
+ restoration.motion_plan.endpoint_policy
+ )
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then