summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/sequence_coordinator.lua27
-rw-r--r--tests/run.lua19
2 files changed, 46 insertions, 0 deletions
diff --git a/lua/clever_f/sequence_coordinator.lua b/lua/clever_f/sequence_coordinator.lua
index 0da3ef3..10949bd 100644
--- a/lua/clever_f/sequence_coordinator.lua
+++ b/lua/clever_f/sequence_coordinator.lua
@@ -48,6 +48,33 @@ function SequenceCoordinator:validate_primary_descriptor(value)
return M.validate_primary_descriptor(value)
end
+local function require_primary_reader(host)
+ if type(host) ~= "table"
+ or type(host.read_mode) ~= "function"
+ or type(host.read_cursor) ~= "function"
+ or type(host.read_count) ~= "function"
+ or type(host.read_macro_state) ~= "function"
+ then
+ fail("SequenceCoordinator host must provide primary action state", 3)
+ end
+ return host
+end
+
+function SequenceCoordinator:read_primary_invocation()
+ local host = require_primary_reader(coordinator_records[self].host)
+ local context = domain.ModeContext.from_full_mode(host:read_mode())
+ local position = domain.Position.coerce(host:read_cursor())
+ local count = domain.Count.new(host:read_count())
+ local macro_state = domain.MacroState.new(host:read_macro_state())
+ return {
+ context = context,
+ position = position,
+ origin = position,
+ count = count,
+ macro_state = macro_state,
+ }
+end
+
function SequenceCoordinator:primary(value)
return self:validate_primary_descriptor(value)
end
diff --git a/tests/run.lua b/tests/run.lua
index aced20a..6752ae3 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -7079,6 +7079,25 @@ test("Primary coordination accepts only the four motion descriptors", function()
end, "clever-f: Invalid mapping 'x'")
end)
+test("Primary coordination reads normalized invocation state", function()
+ local host = MemoryHost.new({
+ mode = "nov",
+ cursor = { line = 2, byte_column = 4 },
+ count = 3,
+ macro_register = "q",
+ buffer_lines = { "one", "text" },
+ })
+ local invocation = sequence_coordinator.new({ host = host })
+ :read_primary_invocation()
+
+ same(domain.ModeContext.from_full_mode("no"), invocation.context)
+ same(domain.Position.new(2, 4), invocation.position)
+ same(invocation.position, invocation.origin)
+ same(3, invocation.count.value)
+ truthy(invocation.macro_state.executing)
+ same("q", invocation.macro_state.register)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then