diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 10:49:08 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 10:49:08 +0200 |
| commit | 33e93f67e78d3a502401442f80ff2572ed35d5dd (patch) | |
| tree | 99cf98f33fbc47f56269ac6ac8392d1393b683cf | |
| parent | 80206387c712c2ef78eb1ce6546aa3d3969d7bb8 (diff) | |
Compare command destinations
| -rw-r--r-- | lua/clever_f/motion_executor.lua | 7 | ||||
| -rw-r--r-- | tests/run.lua | 14 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lua/clever_f/motion_executor.lua b/lua/clever_f/motion_executor.lua index 3d6caf5..9718640 100644 --- a/lua/clever_f/motion_executor.lua +++ b/lua/clever_f/motion_executor.lua @@ -25,6 +25,12 @@ function M.execution_path(context) return M.ExecutionPath.COMMAND end +function M.moved_forward(origin, destination) + origin = domain.Position.coerce(origin) + destination = domain.Position.coerce(destination) + return domain.Position.compare(destination, origin) > 0 +end + local function copy_options(options) local result = {} for key, value in pairs(options or {}) do @@ -141,6 +147,7 @@ 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) return domain.ActionOutcome.from_search(outcome, request.plan.descriptor) end diff --git a/tests/run.lua b/tests/run.lua index 02f5e2d..dd0da6f 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -3231,6 +3231,20 @@ test("Incomplete command execution preserves successful history", function() same(25, state.repeat_timestamp_ms) end) +test("Complete command direction compares destination with saved origin", function() + local origin = domain.Position.new(2, 3) + truthy( + motion_executor.moved_forward(origin, domain.Position.new(2, 4)) + ) + truthy( + motion_executor.moved_forward(origin, domain.Position.new(3, 1)) + ) + falsy( + motion_executor.moved_forward(origin, domain.Position.new(2, 2)) + ) + falsy(motion_executor.moved_forward(origin, origin)) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then |
