aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorechasnovski <evgeni.chasnovski@gmail.com>2021-02-07 18:01:52 +0200
committerStephan Seitz <stephan.lauf@yahoo.de>2021-02-21 20:25:26 +0100
commit079dafa36efa5499e2e6dc5ddf89f7f0385fa356 (patch)
treee9f396d7455bb81c83605911ffdbc2be786ebd63
parentAdd `selection_mode` argument to `ts_utils.update_selection()`. (diff)
downloadnvim-treesitter-079dafa36efa5499e2e6dc5ddf89f7f0385fa356.tar
nvim-treesitter-079dafa36efa5499e2e6dc5ddf89f7f0385fa356.tar.gz
nvim-treesitter-079dafa36efa5499e2e6dc5ddf89f7f0385fa356.tar.bz2
nvim-treesitter-079dafa36efa5499e2e6dc5ddf89f7f0385fa356.tar.lz
nvim-treesitter-079dafa36efa5499e2e6dc5ddf89f7f0385fa356.tar.xz
nvim-treesitter-079dafa36efa5499e2e6dc5ddf89f7f0385fa356.tar.zst
nvim-treesitter-079dafa36efa5499e2e6dc5ddf89f7f0385fa356.zip
Add "v", "V", "<C-v>" as valid options of `selection_mode`.
-rw-r--r--lua/nvim-treesitter/ts_utils.lua9
1 files changed, 5 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua
index 6f31ef7e6..93ac7027f 100644
--- a/lua/nvim-treesitter/ts_utils.lua
+++ b/lua/nvim-treesitter/ts_utils.lua
@@ -131,7 +131,8 @@ function M.highlight_range(range, buf, hl_namespace, hl_group)
end
-- Set visual selection to node
--- @param selection_mode One of "charwise" (default), "linewise", "blockwise"
+-- @param selection_mode One of "charwise" (default) or "v", "linewise" or "V",
+-- "blockwise" or "<C-v>" (as a string with 5 characters or a single character)
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)
@@ -152,10 +153,10 @@ function M.update_selection(buf, node, selection_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
+ local mode_string = vim.api.nvim_replace_termcodes(
+ v_table[selection_mode] or selection_mode, true, true, true
)
- vim.cmd(command)
+ vim.cmd("normal! " .. mode_string)
-- Convert exclusive end position to inclusive
if end_col == 1 then