refactor(defaults): use getregion() for default * and # mappings

This commit is contained in:
zeertzjq 2024-02-23 08:12:46 +08:00 committed by GitHub
parent df1795cd6b
commit eb4783fb6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,27 +4,9 @@ do
--- ---
--- See |v_star-default| and |v_#-default| --- See |v_star-default| and |v_#-default|
do do
local function region_chunks(region)
local chunks = {}
local maxcol = vim.v.maxcol
for line, cols in vim.spairs(region) do
local endcol = cols[2] == maxcol and -1 or cols[2]
local chunk = vim.api.nvim_buf_get_text(0, line, cols[1], line, endcol, {})[1]
table.insert(chunks, chunk)
end
return chunks
end
local function _visual_search(cmd) local function _visual_search(cmd)
assert(cmd == '/' or cmd == '?') assert(cmd == '/' or cmd == '?')
local region = vim.region( local chunks = vim.fn.getregion('.', 'v', vim.fn.mode())
0,
'.',
'v',
vim.api.nvim_get_mode().mode:sub(1, 1),
vim.o.selection == 'inclusive'
)
local chunks = region_chunks(region)
local esc_chunks = vim local esc_chunks = vim
.iter(chunks) .iter(chunks)
:map(function(v) :map(function(v)