From 35b29e0a23efe5fe9660ac53154cbe85b409a754 Mon Sep 17 00:00:00 2001 From: Jackson Moore Date: Fri, 4 Sep 2026 10:19:39 +0200 Subject: Bound target start enumeration --- lua/clever_f/destination_engine.lua | 8 +++-- tests/run.lua | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/lua/clever_f/destination_engine.lua b/lua/clever_f/destination_engine.lua index c17dc83..2ff4c7a 100644 --- a/lua/clever_f/destination_engine.lua +++ b/lua/clever_f/destination_engine.lua @@ -60,12 +60,16 @@ local function calculation_inputs(view, origin, plan, count, first_move) } end -local function next_matching_start(request, origin) - local candidates = request.view:iter_strict( +local function candidate_starts(request, origin) + return request.view:iter_strict( origin, request.plan.descriptor.direction, request.bounds ) +end + +local function next_matching_start(request, origin) + local candidates = candidate_starts(request, origin) while true do local position, character = candidates() diff --git a/tests/run.lua b/tests/run.lua index e84c12a..d657870 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -2238,6 +2238,77 @@ test("DestinationEngine enumerates target starts in motion order", function() list_same({ "b:(1,2)", "a:(1,1)" }, visits) end) +test("DestinationEngine stops target starts at selected boundaries", function() + local view = text_topology.new({ "axa", "", "axa" }, "utf-8") + local target_match = target_plan.build(target("a"), matching_policy()) + local engine = destination_engine.new() + local line_forward = motion_plan.build(target_match, "f", "current_line") + local buffer_forward = motion_plan.build(target_match, "f", "buffer") + local line_backward = motion_plan.build(target_match, "F", "current_line") + local buffer_backward = motion_plan.build(target_match, "F", "buffer") + + same( + domain.Position.new(1, 3), + engine:calculate( + view, + domain.Position.new(1, 1), + line_forward, + 1, + true + ).endpoint + ) + same( + domain.SearchStatus.BOUNDARY_BEFORE_ANY, + engine:calculate( + view, + domain.Position.new(1, 3), + line_forward, + 1, + false + ).status + ) + same( + domain.Position.new(3, 1), + engine:calculate( + view, + domain.Position.new(1, 3), + buffer_forward, + 1, + false + ).endpoint + ) + same( + domain.Position.new(3, 1), + engine:calculate( + view, + domain.Position.new(3, 3), + line_backward, + 1, + true + ).endpoint + ) + same( + domain.Position.new(1, 3), + engine:calculate( + view, + domain.Position.new(3, 1), + buffer_backward, + 1, + false + ).endpoint + ) + same( + domain.Position.new(3, 1), + engine:calculate( + view, + domain.Position.new(2, 1), + buffer_forward, + 1, + true + ).endpoint + ) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then -- cgit v1.2.3