summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/sequence_coordinator.lua32
-rw-r--r--tests/run.lua25
2 files changed, 51 insertions, 6 deletions
diff --git a/lua/clever_f/sequence_coordinator.lua b/lua/clever_f/sequence_coordinator.lua
index 837acf5..350c026 100644
--- a/lua/clever_f/sequence_coordinator.lua
+++ b/lua/clever_f/sequence_coordinator.lua
@@ -261,6 +261,31 @@ function SequenceCoordinator:evaluate_repeat_timeout(invocation)
}
end
+function SequenceCoordinator:stored_primary_resolution(
+ invocation,
+ pressed_descriptor,
+ timeout
+)
+ if type(invocation) ~= "table" or not domain.ModeContext.is(invocation.context) then
+ fail("stored primary resolution requires invocation state", 2)
+ end
+ pressed_descriptor = self:validate_primary_descriptor(pressed_descriptor)
+ local state = coordinator_records[self].state
+ local stored_descriptor = state:get_previous_descriptor(invocation.context)
+ local stored_target = state:get_previous_target(invocation.context)
+ if stored_descriptor == nil or stored_target == nil then
+ fail("repeat-eligible primary state must contain descriptor and target", 2)
+ end
+ return {
+ kind = "repeat",
+ invocation = invocation,
+ pressed_descriptor = pressed_descriptor,
+ timeout = timeout,
+ stored_descriptor = stored_descriptor,
+ target = stored_target,
+ }
+end
+
function SequenceCoordinator:primary(value)
local descriptor = self:validate_primary_descriptor(value)
local invocation = self:read_primary_invocation()
@@ -284,12 +309,7 @@ function SequenceCoordinator:primary(value)
end
return self:resolve_acquisition(descriptor, invocation)
end
- return {
- kind = "repeat",
- invocation = invocation,
- pressed_descriptor = descriptor,
- timeout = timeout,
- }
+ return self:stored_primary_resolution(invocation, descriptor, timeout)
end
function M.new(options)
diff --git a/tests/run.lua b/tests/run.lua
index 05a37f7..6186d7b 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -7375,6 +7375,31 @@ test("Expired primary repetition resets resources and reacquires pressed key", f
falsy(host:timers()[timer].active)
end)
+test("Timely primary repetition reads current-context sequence values", function()
+ local _, transitions = fresh_sequence_state()
+ local landing = domain.Position.new(1, 3)
+ local normal_target = target("a")
+ local visual_target = target("b")
+ transitions:BeginAcquisition("n", "F")
+ transitions:CommitAcquiredTarget("n", normal_target)
+ transitions:CommitCommandSuccess("n", landing, false)
+ transitions:BeginAcquisition("v", "t")
+ transitions:CommitAcquiredTarget("v", visual_target)
+ transitions:CommitVisualSuccess("v", landing)
+ local host = MemoryHost.new({
+ buffer_lines = { "ababa" },
+ cursor = landing,
+ mode = "n",
+ })
+
+ local resolution = sequence_coordinator.new({ host = host }):primary("t")
+
+ same("repeat", resolution.kind)
+ same(domain.Descriptor.FIND_BACKWARD, resolution.stored_descriptor)
+ same(normal_target, resolution.target)
+ same(domain.Descriptor.TILL_FORWARD, resolution.pressed_descriptor)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then