diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 10:24:05 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 10:24:05 +0200 |
| commit | de9b718b8642fa554ac1533a0e0d064bad2979d3 (patch) | |
| tree | 78705ba4dedca94bc092aafb960103591eee1e2a /lua/clever_f/motion_plan.lua | |
| parent | 6449ffa5406ab4573f2148f23da06ed8d10d6ac4 (diff) | |
Select regular endpoint policies
Diffstat (limited to 'lua/clever_f/motion_plan.lua')
| -rw-r--r-- | lua/clever_f/motion_plan.lua | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lua/clever_f/motion_plan.lua b/lua/clever_f/motion_plan.lua index 362b978..1d0b4e3 100644 --- a/lua/clever_f/motion_plan.lua +++ b/lua/clever_f/motion_plan.lua @@ -91,6 +91,54 @@ function MotionPlanFactory:build( }) end +local function selection_option(selection) + if selection == nil then + return domain.SelectionOption.INCLUSIVE + end + if domain.Selection.is(selection) then + return selection.option + end + if domain.SelectionOption.is(selection) then + return selection + end + if type(selection) == "table" and selection.option ~= nil then + return domain.SelectionOption.from_string(selection.option) + end + return domain.SelectionOption.from_string(selection) +end + +function M.endpoint_policy(context, selection) + context = domain.ModeContext.from_full_mode(context) + local option = selection_option(selection) + local visual_kind = context.visual_kind + if option == domain.SelectionOption.EXCLUSIVE + and (visual_kind == domain.SelectionKind.CHARACTER + or visual_kind == domain.SelectionKind.LINE) + then + return domain.EndpointPolicy.VISUAL_EXCLUSIVE + end + return domain.EndpointPolicy.REGULAR +end + +function MotionPlanFactory:endpoint_policy(context, selection) + return M.endpoint_policy(context, selection) +end + +function MotionPlanFactory:build_for_context( + target_plan, + effective_descriptor, + context, + selection, + search_scope +) + return self:build( + target_plan, + effective_descriptor, + search_scope, + self:endpoint_policy(context, selection) + ) +end + function M.new(options) return MotionPlanFactory.new(options) end @@ -110,8 +158,26 @@ function M.build( ) end +function M.build_for_context( + target_plan, + effective_descriptor, + context, + selection, + search_scope, + options +) + return MotionPlanFactory.new(options):build_for_context( + target_plan, + effective_descriptor, + context, + selection, + search_scope + ) +end + M.create = M.build M.resolve = M.build +M.for_context = M.build_for_context setmetatable(M, { __call = function(_, options) |
