From f3ed370643dee45a3ea253a780cd30e74361d2bd Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Wed, 5 Aug 2020 18:11:01 +0200 Subject: Textobject goto: treat end differently that start --- lua/nvim-treesitter/textobjects.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/textobjects.lua b/lua/nvim-treesitter/textobjects.lua index 4ea9c4bb2..1220acedd 100644 --- a/lua/nvim-treesitter/textobjects.lua +++ b/lua/nvim-treesitter/textobjects.lua @@ -87,17 +87,17 @@ local function swap_textobject(query_string, direction) local overlapping_range_ok = false local same_parent = true for _ = 1, math.abs(direction), step do - if direction > 0 then - ts_utils.swap_nodes(textobject_range, - M.next_textobject(node, query_string, same_parent, overlapping_range_ok, bufnr), - bufnr, - "yes, set cursor!") - else - ts_utils.swap_nodes(textobject_range, - M.previous_textobject(node, query_string, same_parent, overlapping_range_ok, bufnr), - bufnr, - "yes, set cursor!") - end + if direction > 0 then + ts_utils.swap_nodes(textobject_range, + M.next_textobject(node, query_string, same_parent, overlapping_range_ok, bufnr), + bufnr, + "yes, set cursor!") + else + ts_utils.swap_nodes(textobject_range, + M.previous_textobject(node, query_string, same_parent, overlapping_range_ok, bufnr), + bufnr, + "yes, set cursor!") + end end end @@ -146,7 +146,6 @@ function M.next_textobject(node, query_string, same_parent, overlapping_range_ok local search_start, _ if overlapping_range_ok then _, _, search_start = node:start() - search_start = search_start - 1 else _, _, search_start = node:end_() end @@ -159,7 +158,7 @@ function M.next_textobject(node, query_string, same_parent, overlapping_range_ok if not same_parent or node:parent() == match.node:parent() then local _, _, start = match.node:start() local _, _, end_ = match.node:end_() - return start > search_start and end_ > node_end + return start > search_start and end_ >= node_end end end, function(match) -- cgit v1.2.3-70-g09d2