summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/composition_root.lua27
-rw-r--r--tests/run.lua24
2 files changed, 50 insertions, 1 deletions
diff --git a/lua/clever_f/composition_root.lua b/lua/clever_f/composition_root.lua
index 051520c..0ea9675 100644
--- a/lua/clever_f/composition_root.lua
+++ b/lua/clever_f/composition_root.lua
@@ -19,6 +19,13 @@ M.ACTION_NAMES = {
"RepeatSameDirection",
"RepeatOppositeDirection",
}
+M.DEFAULT_MAPPING_MODES = { "n", "x", "o" }
+M.DEFAULT_MAPPINGS = {
+ { lhs = "f", action = "StartFindForward" },
+ { lhs = "F", action = "StartFindBackward" },
+ { lhs = "t", action = "StartTillForward" },
+ { lhs = "T", action = "StartTillBackward" },
+}
local ACTION_INVOCATIONS = {
StartFindForward = function(facade)
@@ -124,6 +131,22 @@ local function register_logical_actions(record)
return registrations
end
+local function register_default_mappings(record, setup)
+ local registrations = {}
+ if not setup.install_default_mappings then
+ return registrations
+ end
+ for _, mapping in ipairs(M.DEFAULT_MAPPINGS) do
+ registrations[mapping.lhs] = record.host:register_mapping(
+ M.DEFAULT_MAPPING_MODES,
+ mapping.lhs,
+ mapping.action,
+ {}
+ )
+ end
+ return registrations
+end
+
function CompositionRoot:activate()
local record = root_records[self]
if record.activation == nil then
@@ -137,13 +160,15 @@ function CompositionRoot:activate()
end,
{ owner = "clever_f", lifecycle = "colorscheme" }
)
+ local actions = register_logical_actions(record)
record.activation = {
state = record.state,
setup = setup,
feedback = feedback_activation,
highlights = highlights,
colorscheme_registration = colorscheme_registration,
- actions = register_logical_actions(record),
+ actions = actions,
+ mappings = register_default_mappings(record, setup),
}
end
return record.activation
diff --git a/tests/run.lua b/tests/run.lua
index 4e1649a..d30aea4 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -7206,6 +7206,30 @@ test("Core activation checks mapping suppression by sentinel presence", function
end
end)
+test("Core activation installs four default mappings in required modes", function()
+ fresh_sequence_state()
+ local host = MemoryHost.new()
+ local activation = composition_root.new({ host = host }):activate()
+ local mappings = host:mappings()
+
+ same(4, map_size(activation.mappings))
+ for _, expected in ipairs(composition_root.DEFAULT_MAPPINGS) do
+ local identity = activation.mappings[expected.lhs]
+ local actual = mappings[identity]
+ same(expected.lhs, actual.lhs)
+ same(expected.action, actual.action)
+ list_same(composition_root.DEFAULT_MAPPING_MODES, actual.modes)
+ end
+
+ fresh_sequence_state()
+ local configuration = {}
+ configuration[policy.DEFAULT_MAP_SUPPRESSION_SENTINEL] = false
+ local suppressed_host = MemoryHost.new({ configuration = configuration })
+ local suppressed = composition_root.new({ host = suppressed_host }):activate()
+ same(0, map_size(suppressed.mappings))
+ same(0, map_size(suppressed_host:mappings()))
+end)
+
test("Primary coordination accepts only the four motion descriptors", function()
local coordinator = sequence_coordinator.new({ host = MemoryHost.new() })
for _, value in ipairs({ "f", "F", "t", "T" }) do