summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 10:21:30 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 10:21:30 +0200
commit1a9f90afcc6e5e00a94dd188a5361a894d06e257 (patch)
tree94cf2f1226af5ecf6381c5eb908bb9efa7227ff6
parent51d029e037f233e3239d426d151630ec4897d4fb (diff)
Transform backward TILL destinations
-rw-r--r--lua/clever_f/destination_engine.lua2
-rw-r--r--tests/run.lua34
2 files changed, 35 insertions, 1 deletions
diff --git a/lua/clever_f/destination_engine.lua b/lua/clever_f/destination_engine.lua
index 6d9ceca..ed3b7b2 100644
--- a/lua/clever_f/destination_engine.lua
+++ b/lua/clever_f/destination_engine.lua
@@ -90,7 +90,7 @@ local function regular_destination(request, target_position)
if descriptor.direction == domain.Direction.FORWARD then
return request.view:predecessor(target_position)
end
- return target_position
+ return request.view:successor(target_position)
end
local function target_destination(request, target_position)
diff --git a/tests/run.lua b/tests/run.lua
index e11bf1f..e045a7e 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -2383,6 +2383,40 @@ test("Forward TILL destinations use target predecessors", function()
truthy(view:is_valid_cursor_position(cross_line.endpoint))
end)
+test("Backward TILL destinations use target successors", function()
+ local engine = destination_engine.new()
+ local same_line_view = text_topology.new({ "xabx" }, "utf-8")
+ local till_a = motion_plan.build(
+ target_plan.build(target("a"), matching_policy()),
+ "T"
+ )
+ same(
+ domain.Position.new(1, 3),
+ engine:calculate(
+ same_line_view,
+ domain.Position.new(1, 4),
+ till_a,
+ 1,
+ true
+ ).endpoint
+ )
+
+ local cross_line_view = text_topology.new({ "x", "abc" }, "utf-8")
+ local till_x = motion_plan.build(
+ target_plan.build(target("x"), matching_policy()),
+ "T"
+ )
+ local cross_line = engine:calculate(
+ cross_line_view,
+ domain.Position.new(2, 2),
+ till_x,
+ 1,
+ true
+ )
+ same(domain.Position.new(2, 1), cross_line.endpoint)
+ truthy(cross_line_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