mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 02:40:09 -04:00
Add selection_mode argument to ts_utils.update_selection().
This commit is contained in:
parent
1ab424d384
commit
a34459213e
1 changed files with 12 additions and 2 deletions
|
|
@ -131,7 +131,9 @@ function M.highlight_range(range, buf, hl_namespace, hl_group)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set visual selection to node
|
-- Set visual selection to node
|
||||||
function M.update_selection(buf, node)
|
-- @param selection_mode One of "charwise" (default), "linewise", "blockwise"
|
||||||
|
function M.update_selection(buf, node, selection_mode)
|
||||||
|
selection_mode = selection_mode or "charwise"
|
||||||
local start_row, start_col, end_row, end_col = M.get_node_range(node)
|
local start_row, start_col, end_row, end_col = M.get_node_range(node)
|
||||||
|
|
||||||
if end_row == vim.fn.line('$') then
|
if end_row == vim.fn.line('$') then
|
||||||
|
|
@ -145,7 +147,15 @@ function M.update_selection(buf, node)
|
||||||
end_col = end_col + 1
|
end_col = end_col + 1
|
||||||
|
|
||||||
vim.fn.setpos(".", { buf, start_row, start_col, 0 })
|
vim.fn.setpos(".", { buf, start_row, start_col, 0 })
|
||||||
vim.fn.nvim_exec("normal! v", false)
|
|
||||||
|
-- Start visual selection in appropriate mode
|
||||||
|
local v_table = {charwise = "v", linewise = "V", blockwise = "<C-v>"}
|
||||||
|
---- Call to `nvim_replace_termcodes()` is needed for sending appropriate
|
||||||
|
---- command to enter blockwise mode
|
||||||
|
local command = vim.api.nvim_replace_termcodes(
|
||||||
|
"normal! " .. v_table[selection_mode], true, true, true
|
||||||
|
)
|
||||||
|
vim.cmd(command)
|
||||||
|
|
||||||
-- Convert exclusive end position to inclusive
|
-- Convert exclusive end position to inclusive
|
||||||
if end_col == 1 then
|
if end_col == 1 then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue