summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/motion_executor.lua18
-rw-r--r--tests/run.lua24
2 files changed, 41 insertions, 1 deletions
diff --git a/lua/clever_f/motion_executor.lua b/lua/clever_f/motion_executor.lua
index 9718640..b66f0b7 100644
--- a/lua/clever_f/motion_executor.lua
+++ b/lua/clever_f/motion_executor.lua
@@ -31,6 +31,18 @@ function M.moved_forward(origin, destination)
return domain.Position.compare(destination, origin) > 0
end
+function M.command_moved_forward(descriptor, origin, destination)
+ descriptor = domain.Descriptor.from_string(descriptor)
+ origin = domain.Position.coerce(origin)
+ destination = domain.Position.coerce(destination)
+ if descriptor.family == domain.Family.TILL
+ and domain.Position.stationary(origin, destination)
+ then
+ return false
+ end
+ return M.moved_forward(origin, destination)
+end
+
local function copy_options(options)
local result = {}
for key, value in pairs(options or {}) do
@@ -147,7 +159,11 @@ function MotionExecutor:_execute_command(request)
if not outcome.complete then
return domain.ActionOutcome.from_search(outcome, request.plan.descriptor)
end
- request.moved_forward = M.moved_forward(origin, outcome.endpoint)
+ request.moved_forward = M.command_moved_forward(
+ request.plan.descriptor,
+ origin,
+ outcome.endpoint
+ )
return domain.ActionOutcome.from_search(outcome, request.plan.descriptor)
end
diff --git a/tests/run.lua b/tests/run.lua
index dd0da6f..2b1613c 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -3245,6 +3245,30 @@ test("Complete command direction compares destination with saved origin", functi
falsy(motion_executor.moved_forward(origin, origin))
end)
+test("A stationary first TILL completion is not forward movement", function()
+ local origin = domain.Position.new(1, 1)
+ falsy(motion_executor.command_moved_forward("t", origin, origin))
+
+ local host = MemoryHost.new({
+ buffer_lines = { "ab" },
+ cursor = origin,
+ })
+ local plan = motion_plan.build(
+ target_plan.build(target("b"), matching_policy()),
+ "t"
+ )
+ local outcome = motion_executor.new(host):execute(
+ text_topology.from_host(host),
+ "n",
+ plan,
+ 1,
+ true
+ )
+ same(domain.ActionKind.MOVEMENT, outcome.kind)
+ same(origin, outcome.position)
+ same(1, outcome.successful_steps)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then