-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.lua
More file actions
56 lines (44 loc) · 2.3 KB
/
Copy pathsetup.lua
File metadata and controls
56 lines (44 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local exit = require("smart-motion.core.events.exit")
local utils = require("smart-motion.utils")
local consts = require("smart-motion.consts")
local state = require("smart-motion.core.state")
local module_loader = require("smart-motion.utils.module_loader")
local log = require("smart-motion.core.log")
local filetype_dispatch = require("smart-motion.core.engine.filetype_dispatch")
local EXIT_TYPE = consts.EXIT_TYPE
local M = {}
function M.run(trigger_key)
local motion = require("smart-motion.motions").get_by_key(trigger_key)
exit.throw_if(not motion, EXIT_TYPE.EARLY_EXIT)
local ctx, cfg, motion_state = utils.prepare_motion()
exit.throw_if(not ctx or not cfg or not motion_state, EXIT_TYPE.EARLY_EXIT)
-- Shallow copy so infer mutations don't leak to the registry entry
motion_state.motion = vim.tbl_extend("force", {}, motion)
filetype_dispatch.apply(ctx, motion_state)
-- Set motion_key to the trigger key for direct motions.
-- For operator motions (infer=true), infer.run will override this with the composed key.
motion_state.motion_key = trigger_key
-- For infer motions (d, y, c), skip loading the extractor here — infer.run()
-- will determine the correct extractor from the composable motion (e.g. w, b, e).
local load_keys = nil
if motion_state.motion.infer then
load_keys = { "collector", "modifier", "filter", "visualizer", "action" }
end
local modules = module_loader.get_modules(ctx, cfg, motion_state, load_keys)
-- The modules might have motion_state they would like to set
-- Use motion_state.motion (the shallow copy, possibly modified by filetype_dispatch)
-- instead of the original registry entry, so overridden metadata is preserved.
motion_state = state.merge_motion_state(motion_state, motion_state.motion, modules)
-- Apply any per-mode motion_state override (e.g. o = { exclude_target = true })
-- Normalize ctx.mode to keymap-style single char: "no" -> "o", "v"/"V" -> "x", etc.
if motion_state.motion.per_mode_motion_state then
local mode_key = ctx.mode:find("o") and "o" or ctx.mode:sub(1, 1)
local mode_override = motion_state.motion.per_mode_motion_state[mode_key]
or motion_state.motion.per_mode_motion_state[ctx.mode]
if mode_override then
motion_state = vim.tbl_deep_extend("force", motion_state, mode_override)
end
end
return ctx, cfg, motion_state
end
return M