summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 10:20:24 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 10:20:24 +0200
commitbd0a050c72ece85e071abe176962b256232082b8 (patch)
tree51d8a720847ae990bd58a0415181fb467d6baaa9
parent35b29e0a23efe5fe9660ac53154cbe85b409a754 (diff)
Transform FIND destinations
-rw-r--r--lua/clever_f/destination_engine.lua14
-rw-r--r--tests/run.lua38
2 files changed, 51 insertions, 1 deletions
diff --git a/lua/clever_f/destination_engine.lua b/lua/clever_f/destination_engine.lua
index 2ff4c7a..e0ddcca 100644
--- a/lua/clever_f/destination_engine.lua
+++ b/lua/clever_f/destination_engine.lua
@@ -82,13 +82,25 @@ local function next_matching_start(request, origin)
end
end
+local function regular_destination(request, target_position)
+ if request.plan.descriptor.family == domain.Family.FIND then
+ return target_position
+ end
+ return target_position
+end
+
+local function target_destination(request, target_position)
+ return regular_destination(request, target_position)
+end
+
function DestinationEngine:calculate(view, origin, plan, count, first_move)
local request = calculation_inputs(view, origin, plan, count, first_move)
local target_position = next_matching_start(request, request.origin)
if target_position == nil then
return domain.SearchOutcome.boundary_before_any(request.origin)
end
- return domain.SearchOutcome.complete(target_position, 1)
+ local destination = target_destination(request, target_position)
+ return domain.SearchOutcome.complete(destination, 1)
end
function M.new()
diff --git a/tests/run.lua b/tests/run.lua
index d657870..183c9af 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -2309,6 +2309,44 @@ test("DestinationEngine stops target starts at selected boundaries", function()
)
end)
+test("FIND destinations use matching target positions", function()
+ local view = text_topology.new({ "poge huga hiyo poyo" }, "utf-8")
+ local engine = destination_engine.new()
+ local h = target_plan.build(target("h"), matching_policy())
+ local forward = motion_plan.build(h, "f")
+ local backward = motion_plan.build(h, "F")
+
+ local first = engine:calculate(
+ view,
+ domain.Position.new(1, 1),
+ forward,
+ 1,
+ true
+ )
+ same(domain.Position.new(1, 6), first.endpoint)
+ local second = engine:calculate(view, first.endpoint, forward, 1, false)
+ same(domain.Position.new(1, 11), second.endpoint)
+ same(
+ domain.Position.new(1, 6),
+ engine:calculate(view, second.endpoint, backward, 1, false).endpoint
+ )
+
+ local o = target_plan.build(target("o"), matching_policy())
+ local find_o_backward = motion_plan.build(o, "F")
+ local previous = engine:calculate(
+ view,
+ domain.Position.new(1, 19),
+ find_o_backward,
+ 1,
+ true
+ )
+ same(domain.Position.new(1, 17), previous.endpoint)
+ same(
+ domain.Position.new(1, 14),
+ engine:calculate(view, previous.endpoint, find_o_backward, 1, false).endpoint
+ )
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then