diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/clever_f/destination_engine.lua | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/lua/clever_f/destination_engine.lua b/lua/clever_f/destination_engine.lua index 836d190..0ae2314 100644 --- a/lua/clever_f/destination_engine.lua +++ b/lua/clever_f/destination_engine.lua @@ -68,20 +68,6 @@ local function candidate_starts(request, origin) ) end -local function next_matching_start(request, origin) - local candidates = candidate_starts(request, origin) - - while true do - local position, character = candidates() - if position == nil then - return nil - end - if request.plan.target_plan:matches(character, position, request.view) then - return position - end - end -end - local function regular_destination(request, target_position) local descriptor = request.plan.descriptor if descriptor.family == domain.Family.FIND then @@ -106,13 +92,47 @@ local function target_destination(request, target_position) return regular_destination(request, target_position) end +local function strict_destination(descriptor, destination, origin) + local comparison = domain.Position.compare(destination, origin) + if descriptor.direction == domain.Direction.FORWARD then + return comparison > 0 + end + return comparison < 0 +end + +local function acceptable_destination(request, destination, origin) + if request.plan.descriptor.family == domain.Family.FIND then + return strict_destination(request.plan.descriptor, destination, origin) + end + return true +end + +local function next_destination(request, origin) + local candidates = candidate_starts(request, origin) + + while true do + local target_position, character = candidates() + if target_position == nil then + return nil + end + if request.plan.target_plan:matches( + character, + target_position, + request.view + ) then + local destination = target_destination(request, target_position) + if destination ~= nil + and acceptable_destination(request, destination, origin) + then + return destination + end + end + end +end + function DestinationEngine:calculate(view, origin, plan, count, first_move) local request = calculation_inputs(view, origin, plan, count, first_move) - local target_position = next_matching_start(request, request.origin) - if target_position == nil then - return domain.SearchOutcome.boundary_before_any(request.origin) - end - local destination = target_destination(request, target_position) + local destination = next_destination(request, request.origin) if destination == nil then return domain.SearchOutcome.boundary_before_any(request.origin) end |
