diff options
| author | echasnovski <evgeni.chasnovski@gmail.com> | 2021-02-07 14:42:14 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2021-02-21 20:25:26 +0100 |
| commit | a34459213e80666e1c6e95f1a38f32d32edeb37d (patch) | |
| tree | 458e015aa7aba6f17a2659b03c9919c63d905293 /lua | |
| parent | add formal_parameters (diff) | |
| download | nvim-treesitter-a34459213e80666e1c6e95f1a38f32d32edeb37d.tar nvim-treesitter-a34459213e80666e1c6e95f1a38f32d32edeb37d.tar.gz nvim-treesitter-a34459213e80666e1c6e95f1a38f32d32edeb37d.tar.bz2 nvim-treesitter-a34459213e80666e1c6e95f1a38f32d32edeb37d.tar.lz nvim-treesitter-a34459213e80666e1c6e95f1a38f32d32edeb37d.tar.xz nvim-treesitter-a34459213e80666e1c6e95f1a38f32d32edeb37d.tar.zst nvim-treesitter-a34459213e80666e1c6e95f1a38f32d32edeb37d.zip | |
Add `selection_mode` argument to `ts_utils.update_selection()`.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/ts_utils.lua | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index a7c38feb6..6f31ef7e6 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -131,7 +131,9 @@ function M.highlight_range(range, buf, hl_namespace, hl_group) end -- 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) if end_row == vim.fn.line('$') then @@ -145,7 +147,15 @@ function M.update_selection(buf, node) end_col = end_col + 1 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 if end_col == 1 then |
