mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-02 19:46:58 -04:00
Refine M.swap_nodes
This commit is contained in:
parent
9dcb96b439
commit
34551231d2
2 changed files with 9 additions and 9 deletions
|
|
@ -69,10 +69,10 @@ M.do_node_movement = function(kind, move_node)
|
|||
node_start_to_vim(destination_node)
|
||||
if move_node then
|
||||
if kind ~= M.NodeMovementKind.down then
|
||||
local new_destination_range = utils.swap_nodes(buf, current_node, destination_node)
|
||||
local _, dst_range = utils.swap_nodes(buf, current_node, destination_node)
|
||||
local root = parsers.get_parser():parse():root()
|
||||
if new_destination_range then
|
||||
local new_destination_node = utils.node_from_lsp_range(root, new_destination_range)
|
||||
if dst_range then
|
||||
local new_destination_node = utils.node_from_lsp_range(root, dst_range)
|
||||
M.current_node[buf] = new_destination_node or current_node
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ function M.replace_node_text(buf, node, replacement_lines)
|
|||
end
|
||||
|
||||
|
||||
--- Swaps the contents of two nodes returning new range of destination (LSP range)
|
||||
--- Swaps the contents of two nodes returning new ranges (LSP ranges)
|
||||
-- @param buf buffer number
|
||||
-- @param source first node
|
||||
-- @param destination second node
|
||||
|
|
@ -148,17 +148,17 @@ function M.swap_nodes(buf, source, destination)
|
|||
local source_text = M.get_node_text(source)
|
||||
local destination_text = M.get_node_text(destination)
|
||||
|
||||
local dst_range
|
||||
local src_range, dst_range
|
||||
|
||||
if dst_end <= src_start then
|
||||
M.replace_node_text(buf, source, destination_text)
|
||||
src_range = M.replace_node_text(buf, source, destination_text)
|
||||
dst_range = M.replace_node_text(buf, destination, source_text)
|
||||
return
|
||||
return
|
||||
elseif src_end <= dst_start then
|
||||
dst_range = M.replace_node_text(buf, destination, source_text)
|
||||
M.replace_node_text(buf, source, destination_text)
|
||||
src_range = M.replace_node_text(buf, source, destination_text)
|
||||
end
|
||||
return dst_range
|
||||
return src_range, dst_range
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue