Range: add option user_defined
This commit is contained in:
parent
a98eeb71c1
commit
e717c0a7d5
@ -86,12 +86,13 @@ function Range.from_lines(buf, start_line, stop_line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param text_obj string
|
---@param text_obj string
|
||||||
---@param opts? { buf?: number; contains_cursor?: boolean; pos?: Pos }
|
---@param opts? { buf?: number; contains_cursor?: boolean; pos?: Pos, user_defined?: boolean }
|
||||||
---@return Range|nil
|
---@return Range|nil
|
||||||
function Range.from_text_object(text_obj, opts)
|
function Range.from_text_object(text_obj, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
if opts.buf == nil then opts.buf = vim.api.nvim_get_current_buf() end
|
if opts.buf == nil then opts.buf = vim.api.nvim_get_current_buf() end
|
||||||
if opts.contains_cursor == nil then opts.contains_cursor = false end
|
if opts.contains_cursor == nil then opts.contains_cursor = false end
|
||||||
|
if opts.user_defined == nil then opts.user_defined = false end
|
||||||
|
|
||||||
---@type "a" | "i"
|
---@type "a" | "i"
|
||||||
local selection_type = text_obj:sub(1, 1)
|
local selection_type = text_obj:sub(1, 1)
|
||||||
@ -118,7 +119,7 @@ function Range.from_text_object(text_obj, opts)
|
|||||||
-- For some reason,
|
-- For some reason,
|
||||||
-- vim.cmd.normal { cmd = 'normal', args = { '""y' .. text_obj }, mods = { silent = true } }
|
-- vim.cmd.normal { cmd = 'normal', args = { '""y' .. text_obj }, mods = { silent = true } }
|
||||||
-- does not work in all cases. We resort to using feedkeys instead:
|
-- does not work in all cases. We resort to using feedkeys instead:
|
||||||
utils.feedkeys('""y' .. text_obj)
|
utils.feedkeys('""y' .. text_obj, opts.user_defined and 'mx' or 'nx') -- 'm' = remap, 'n' = noremap
|
||||||
|
|
||||||
local start = Pos.from_pos "'["
|
local start = Pos.from_pos "'["
|
||||||
local stop = Pos.from_pos "']"
|
local stop = Pos.from_pos "']"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user