diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 12:37:29 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 12:37:29 +0200 |
| commit | adfb712e10e834e19c1541d0657fe4af4489be61 (patch) | |
| tree | c1f0d89e7349f421eff23daac32e74421845aa10 /lua | |
| parent | 4adf0440cdf0bdc9db3dadf89ebda0c9622d2a01 (diff) | |
Compare cursor with input landing
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/clever_f/feedback_service.lua | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua index 0af482a..b8a503d 100644 --- a/lua/clever_f/feedback_service.lua +++ b/lua/clever_f/feedback_service.lua @@ -1,5 +1,6 @@ local domain = require("clever_f.domain") local policy = require("clever_f.policy") +local sequence_state = require("clever_f.sequence_state") local state_transitions = require("clever_f.state_transitions") local text_topology = require("clever_f.text_topology") @@ -101,6 +102,7 @@ local function require_host(host) or type(host.create_highlight) ~= "function" or type(host.remove_highlight) ~= "function" or type(host.read_buffer) ~= "function" + or type(host.read_cursor) ~= "function" or type(host.register_events) ~= "function" or type(host.remove_event_registration) ~= "function" or type(host.supports_cursor_presentation) ~= "function" @@ -145,12 +147,17 @@ function FeedbackService.new(options) options = normalize_options(options) local service = setmetatable({}, FeedbackService) local host = require_host(options.host) + local state = options.state or sequence_state.get() + if not sequence_state.is(state) then + fail("FeedbackService state must be the plugin-global SequenceState", 2) + end service_records[service] = { host = host, policy = require_policy(options.policy or options.policy_service, host), + state = state, transitions = require_transitions( options.transitions or options.state_transitions, - options.state + state ), persistent_requests = {}, owned_finalizer = nil, @@ -458,7 +465,23 @@ function FeedbackService:remove_character_overlays(window) return remove_target_overlays(service_records[self], window) end -function FeedbackService:handle_finalizer_event() +function FeedbackService:cursor_moved_decision() + local record = service_records[self] + local context = record.state.last_input_context + local expected = context and record.state:get_previous_landing(context) or nil + local actual = record.host:read_cursor() + return { + context = context, + expected = expected, + actual = actual, + equal = expected ~= nil and domain.Position.equal(actual, expected), + } +end + +function FeedbackService:handle_finalizer_event(name) + if name == "CursorMoved" then + return self:cursor_moved_decision() + end return false end |
