mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
fix(snippet): use <cmd>call cursor() for visual range
Problem: Change applied ind3e495ce
uses a byte-offset where a virtual column is expected. Solution: Set the cursor directly through a <Cmd> mapping, while making sure the commands are ordered correctly by adding them to the type-ahead buffer. (cherry picked from commit019b2050e1
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
155529b91a
commit
c1d3777db2
@@ -278,15 +278,6 @@ local function select_tabstop(tabstop)
|
||||
vim.api.nvim_feedkeys(keys, 'n', true)
|
||||
end
|
||||
|
||||
--- NOTE: We don't use `vim.api.nvim_win_set_cursor` here because it causes the cursor to end
|
||||
--- at the end of the selection instead of the start.
|
||||
---
|
||||
--- @param row integer
|
||||
--- @param col integer
|
||||
local function move_cursor_to(row, col)
|
||||
feedkeys(string.format('%sG%s|', row, col))
|
||||
end
|
||||
|
||||
local range = tabstop:get_range()
|
||||
local mode = vim.fn.mode()
|
||||
|
||||
@@ -311,13 +302,16 @@ local function select_tabstop(tabstop)
|
||||
end
|
||||
else
|
||||
-- Else, select the tabstop's text.
|
||||
if mode ~= 'n' then
|
||||
feedkeys('<Esc>')
|
||||
end
|
||||
move_cursor_to(range[1] + 1, range[2] + 1)
|
||||
feedkeys('v')
|
||||
move_cursor_to(range[3] + 1, range[4])
|
||||
feedkeys('o<c-g><c-r>_')
|
||||
-- Need this exact order so cannot mix regular API calls with feedkeys, which
|
||||
-- are not executed immediately. Use <Cmd> to set the cursor position.
|
||||
local keys = {
|
||||
mode ~= 'n' and '<Esc>' or '',
|
||||
('<Cmd>call cursor(%s,%s)<CR>'):format(range[1] + 1, range[2] + 1),
|
||||
'v',
|
||||
('<Cmd>call cursor(%s,%s)<CR>'):format(range[3] + 1, range[4]),
|
||||
'o<c-g><c-r>_',
|
||||
}
|
||||
feedkeys(table.concat(keys))
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user