aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorKiyoon Kim <yoonkr33@gmail.com>2023-01-25 19:13:11 +0000
committerStephan Seitz <stephan.seitz@fau.de>2023-01-28 23:52:12 +0100
commitdd94001fcb8b6f933fa8176ca0dda2b064d5be75 (patch)
tree36ee1ed2f57224420c14cbd9f425b31f62790881 /lua
parenthighlights(beancount): update on latest updates (diff)
downloadnvim-treesitter-dd94001fcb8b6f933fa8176ca0dda2b064d5be75.tar
nvim-treesitter-dd94001fcb8b6f933fa8176ca0dda2b064d5be75.tar.gz
nvim-treesitter-dd94001fcb8b6f933fa8176ca0dda2b064d5be75.tar.bz2
nvim-treesitter-dd94001fcb8b6f933fa8176ca0dda2b064d5be75.tar.lz
nvim-treesitter-dd94001fcb8b6f933fa8176ca0dda2b064d5be75.tar.xz
nvim-treesitter-dd94001fcb8b6f933fa8176ca0dda2b064d5be75.tar.zst
nvim-treesitter-dd94001fcb8b6f933fa8176ca0dda2b064d5be75.zip
fix artefact in change mode
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/ts_utils.lua31
1 files changed, 12 insertions, 19 deletions
diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua
index f0409d66d..e9fdc41d2 100644
--- a/lua/nvim-treesitter/ts_utils.lua
+++ b/lua/nvim-treesitter/ts_utils.lua
@@ -260,8 +260,6 @@ end
-- "blockwise" or "<C-v>" (as a string with 5 characters or a single character)
function M.update_selection(buf, node, selection_mode)
local start_row, start_col, end_row, end_col = M.get_vim_range({ M.get_node_range(node) }, buf)
- api.nvim_buf_set_mark(0, "<", start_row, start_col - 1, {})
- api.nvim_buf_set_mark(0, ">", end_row, end_col - 1, {})
local v_table = { charwise = "v", linewise = "V", blockwise = "<C-v>" }
selection_mode = selection_mode or "charwise"
@@ -271,25 +269,20 @@ function M.update_selection(buf, node, selection_mode)
selection_mode = v_table[selection_mode]
end
- -- Call to `nvim_replace_termcodes()` is needed for sending appropriate command to enter blockwise mode
- selection_mode = vim.api.nvim_replace_termcodes(selection_mode, true, true, true)
-
- local previous_mode = vim.fn.visualmode()
-
- -- visualmode() is set to "" when no visual selection has yet been made. Defaults it to "v"
- if previous_mode == "" then
- previous_mode = "v"
- end
-
- if previous_mode == selection_mode then
- selection_mode = ""
+ -- enter visual mode if normal or operator-pending (no) mode
+ -- Why? According to https://learnvimscriptthehardway.stevelosh.com/chapters/15.html
+ -- If your operator-pending mapping ends with some text visually selected, Vim will operate on that text.
+ -- Otherwise, Vim will operate on the text between the original cursor position and the new position.
+ local mode = api.nvim_get_mode()
+ if mode.mode ~= selection_mode then
+ -- Call to `nvim_replace_termcodes()` is needed for sending appropriate command to enter blockwise mode
+ selection_mode = vim.api.nvim_replace_termcodes(selection_mode, true, true, true)
+ api.nvim_cmd({ cmd = "normal", bang = true, args = { selection_mode } }, {})
end
- -- "gv": Start Visual mode with the same area as the previous area and the same mode.
- -- Hence, area will be what we defined in "<" and ">" marks. We only feed `selection_mode` if it is
- -- different than previous `visualmode`, otherwise it will stop visual mode.
- -- bang=true is provided to avoid gv side-effects
- api.nvim_cmd({ cmd = "normal", bang = true, args = { "gv" .. selection_mode } }, {})
+ api.nvim_win_set_cursor(0, { start_row, start_col - 1 })
+ vim.cmd "normal! o"
+ api.nvim_win_set_cursor(0, { end_row, end_col - 1 })
end
-- Byte length of node range