diff options
Diffstat (limited to 'lua/clever_f/host_adapter.lua')
| -rw-r--r-- | lua/clever_f/host_adapter.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lua/clever_f/host_adapter.lua b/lua/clever_f/host_adapter.lua index 7a71fb8..17c29ef 100644 --- a/lua/clever_f/host_adapter.lua +++ b/lua/clever_f/host_adapter.lua @@ -47,6 +47,7 @@ function HostAdapter.new(options) timers = {}, cursor_presentations = {}, events = {}, + dot_repeat = nil, event_order = {}, augroup = nil, } @@ -84,6 +85,75 @@ function HostAdapter:lowercase(value) return result end +function HostAdapter:read_pending_operator() + local operator = self:runtime().v.operator + if operator == nil then + return "" + end + return operator +end + +function HostAdapter:apply_cursor(position) + position = domain.Position.coerce(position) + self:runtime().api.nvim_win_set_cursor( + 0, + { position.line, position.byte_column - 1 } + ) +end + +function HostAdapter:apply_selection(position) + if domain.Selection.is(position) then + if not position.active then + fail("selection movement requires an active selection", 2) + end + position = position.focus + end + return self:apply_cursor(position) +end + +function HostAdapter:set_operator_inclusive(enabled) + if type(enabled) ~= "boolean" then + fail("operator inclusivity must be a Boolean", 2) + end + if enabled then + self:runtime().api.nvim_cmd({ + cmd = "normal", + bang = true, + args = { "v" }, + }, {}) + end +end + +function HostAdapter:register_dot_repeat(payload, callback) + if not domain.DotPayload.is(payload) then + fail("dot-repeat payload must be a DotPayload", 2) + end + if callback ~= nil and type(callback) ~= "function" then + fail("dot-repeat callback must be a function", 2) + end + adapter_records[self].dot_repeat = { + payload = payload, + callback = callback, + } + return payload +end + +function HostAdapter:dot_repeat_payload() + local registration = adapter_records[self].dot_repeat + return registration and registration.payload or nil +end + +function HostAdapter:replay_dot(count) + local registration = adapter_records[self].dot_repeat + if registration == nil or registration.callback == nil then + fail("dot repeat is not executable", 2) + end + return registration.callback( + registration.payload, + domain.Count.new(count) + ) +end + local function next_identity(adapter, prefix) local record = adapter_records[adapter] local identity = prefix .. "-" .. tostring(record.next_identity) |
