switch more APIs away from feedkeys
This commit is contained in:
parent
e717c0a7d5
commit
bdd1d949de
@ -201,17 +201,8 @@ function Pos:find_match(max_chars, invocations)
|
|||||||
local is_closer = vim.tbl_contains(closers, c)
|
local is_closer = vim.tbl_contains(closers, c)
|
||||||
if not is_opener and not is_closer then return nil end
|
if not is_opener and not is_closer then return nil end
|
||||||
|
|
||||||
---@type number
|
local i, _ = vim.iter(is_opener and openers or closers):enumerate():find(function(_, c2) return c == c2 end)
|
||||||
local i
|
local c_match = (is_opener and closers or openers)[i]
|
||||||
---@type string
|
|
||||||
local c_match
|
|
||||||
if is_opener then
|
|
||||||
i, _ = vim.iter(openers):enumerate():find(function(_, c2) return c == c2 end)
|
|
||||||
c_match = closers[i]
|
|
||||||
else
|
|
||||||
i, _ = vim.iter(closers):enumerate():find(function(_, c2) return c == c2 end)
|
|
||||||
c_match = openers[i]
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type Pos|nil
|
---@type Pos|nil
|
||||||
local cur = self
|
local cur = self
|
||||||
@ -224,13 +215,7 @@ function Pos:find_match(max_chars, invocations)
|
|||||||
if max_chars < 0 then return nil end
|
if max_chars < 0 then return nil end
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_opener then
|
return cur:next(is_opener and 1 or -1)
|
||||||
-- scan forward
|
|
||||||
return cur:next()
|
|
||||||
else
|
|
||||||
-- scan backward
|
|
||||||
return cur:next(-1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- scan until we find a match:
|
-- scan until we find a match:
|
||||||
|
@ -116,10 +116,12 @@ function Range.from_text_object(text_obj, opts)
|
|||||||
null_pos:save_to_pos "'["
|
null_pos:save_to_pos "'["
|
||||||
null_pos:save_to_pos "']"
|
null_pos:save_to_pos "']"
|
||||||
|
|
||||||
-- For some reason,
|
vim.cmd.normal {
|
||||||
-- vim.cmd.normal { cmd = 'normal', args = { '""y' .. text_obj }, mods = { silent = true } }
|
cmd = 'normal',
|
||||||
-- does not work in all cases. We resort to using feedkeys instead:
|
bang = not opts.user_defined,
|
||||||
utils.feedkeys('""y' .. text_obj, opts.user_defined and 'mx' or 'nx') -- 'm' = remap, 'n' = noremap
|
args = { '""y' .. text_obj },
|
||||||
|
mods = { silent = true },
|
||||||
|
}
|
||||||
|
|
||||||
local start = Pos.from_pos "'["
|
local start = Pos.from_pos "'["
|
||||||
local stop = Pos.from_pos "']"
|
local stop = Pos.from_pos "']"
|
||||||
@ -403,8 +405,12 @@ function Range:set_visual_selection()
|
|||||||
self.start:save_to_mark 'a'
|
self.start:save_to_mark 'a'
|
||||||
self.stop:save_to_mark 'b'
|
self.stop:save_to_mark 'b'
|
||||||
local mode = self.mode
|
local mode = self.mode
|
||||||
if vim.api.nvim_get_mode().mode == 'n' then utils.feedkeys(mode) end
|
|
||||||
utils.feedkeys '`ao`b'
|
local normal_cmd_args = ''
|
||||||
|
if vim.api.nvim_get_mode().mode == 'n' then normal_cmd_args = normal_cmd_args .. mode end
|
||||||
|
normal_cmd_args = normal_cmd_args .. '`ao`b'
|
||||||
|
vim.cmd { cmd = 'normal', args = { normal_cmd_args }, bang = true }
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user