update lua API to 1-based indices; add renderer
All checks were successful
NeoVim tests / plenary-tests (push) Successful in 11s
All checks were successful
NeoVim tests / plenary-tests (push) Successful in 11s
This commit is contained in:
@@ -1,24 +1,17 @@
|
||||
local Range = require 'u.range'
|
||||
local vim_repeat = require 'u.repeat'
|
||||
|
||||
---@type fun(range: Range): nil|(fun():any)
|
||||
--- @type fun(range: u.Range): nil|(fun():any)
|
||||
local __U__OpKeymapOpFunc_rhs = nil
|
||||
|
||||
--- This is the global utility function used for operatorfunc
|
||||
--- in opkeymap
|
||||
---@type nil|fun(range: Range): fun():any|nil
|
||||
---@param ty 'line'|'char'|'block'
|
||||
--- @type nil|fun(range: u.Range): fun():any|nil
|
||||
--- @param ty 'line'|'char'|'block'
|
||||
-- selene: allow(unused_variable)
|
||||
function __U__OpKeymapOpFunc(ty)
|
||||
function _G.__U__OpKeymapOpFunc(ty)
|
||||
if __U__OpKeymapOpFunc_rhs ~= nil then
|
||||
local range = Range.from_op_func(ty)
|
||||
local repeat_inject = __U__OpKeymapOpFunc_rhs(range)
|
||||
|
||||
vim_repeat.set(function()
|
||||
vim.o.operatorfunc = 'v:lua.__U__OpKeymapOpFunc'
|
||||
if repeat_inject ~= nil and type(repeat_inject) == 'function' then repeat_inject() end
|
||||
vim_repeat.native_repeat()
|
||||
end)
|
||||
__U__OpKeymapOpFunc_rhs(range)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,12 +21,17 @@ end
|
||||
--- g@: tells vim to way for a motion, and then call operatorfunc.
|
||||
--- 2. The operatorfunc is set to a lua function that computes the range being operated over, that
|
||||
--- then calls the original passed callback with said range.
|
||||
---@param mode string|string[]
|
||||
---@param lhs string
|
||||
---@param rhs fun(range: Range): nil|(fun():any) This function may return another function, which is called whenever the operator is repeated
|
||||
---@param opts? vim.keymap.set.Opts
|
||||
--- @param mode string|string[]
|
||||
--- @param lhs string
|
||||
--- @param rhs fun(range: u.Range): nil
|
||||
--- @diagnostic disable-next-line: undefined-doc-name
|
||||
--- @param opts? vim.keymap.set.Opts
|
||||
local function opkeymap(mode, lhs, rhs, opts)
|
||||
vim.keymap.set(mode, lhs, function()
|
||||
-- We don't need to wrap the operation in a repeat, because expr mappings are
|
||||
-- repeated seamlessly by Vim anyway. In addition, the u.repeat:`.` mapping will
|
||||
-- set IS_REPEATING to true, so that callbacks can check if they should used cached
|
||||
-- values.
|
||||
__U__OpKeymapOpFunc_rhs = rhs
|
||||
vim.o.operatorfunc = 'v:lua.__U__OpKeymapOpFunc'
|
||||
return 'g@'
|
||||
|
||||
Reference in New Issue
Block a user