diff options
| -rw-r--r-- | lua/clever_f/destination_engine.lua | 6 | ||||
| -rw-r--r-- | tests/run.lua | 36 |
2 files changed, 41 insertions, 1 deletions
diff --git a/lua/clever_f/destination_engine.lua b/lua/clever_f/destination_engine.lua index e0ddcca..6d9ceca 100644 --- a/lua/clever_f/destination_engine.lua +++ b/lua/clever_f/destination_engine.lua @@ -83,9 +83,13 @@ local function next_matching_start(request, origin) end local function regular_destination(request, target_position) - if request.plan.descriptor.family == domain.Family.FIND then + local descriptor = request.plan.descriptor + if descriptor.family == domain.Family.FIND then return target_position end + if descriptor.direction == domain.Direction.FORWARD then + return request.view:predecessor(target_position) + end return target_position end diff --git a/tests/run.lua b/tests/run.lua index 183c9af..e11bf1f 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -2347,6 +2347,42 @@ test("FIND destinations use matching target positions", function() ) end) +test("Forward TILL destinations use target predecessors", function() + local view = text_topology.new({ + "poge huga hiyo poyo", + "x", + }, "utf-8") + local engine = destination_engine.new() + local till_h = motion_plan.build( + target_plan.build(target("h"), matching_policy()), + "t" + ) + same( + domain.Position.new(1, 5), + engine:calculate( + view, + domain.Position.new(1, 1), + till_h, + 1, + true + ).endpoint + ) + + local till_x = motion_plan.build( + target_plan.build(target("x"), matching_policy()), + "t" + ) + local cross_line = engine:calculate( + view, + domain.Position.new(1, 18), + till_x, + 1, + true + ) + same(domain.Position.new(1, 19), cross_line.endpoint) + truthy(view:is_valid_cursor_position(cross_line.endpoint)) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then |
