Skip to content

Commit

Permalink
Merge pull request #79 from julienvincent/jv/ref-wosqvsrlyxos
Browse files Browse the repository at this point in the history
Fix pairwise drag dragging beyond form boundaries
  • Loading branch information
julienvincent authored Oct 17, 2024
2 parents 350ca86 + fee6321 commit 3db0850
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lua/nvim-paredit/treesitter/pairs.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local ts_utils = require("nvim-paredit.treesitter.utils")
local ts_forms = require("nvim-paredit.treesitter.forms")

local M = {}

Expand All @@ -9,6 +10,10 @@ local M = {}
-- matched nodes.
function M.find_pairwise_nodes(target_node, opts)
local root_node = ts_utils.find_local_root(target_node)
local enclosing_form = ts_forms.find_nearest_form(target_node, opts)
if not enclosing_form then
return
end

local bufnr = vim.api.nvim_get_current_buf()
local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
Expand All @@ -27,9 +32,11 @@ function M.find_pairwise_nodes(target_node, opts)
for id, node in captures do
if query.captures[id] == "pair" then
if not ts_utils.node_is_comment(node, opts) then
table.insert(pairwise_nodes, node)
if node:equal(target_node) then
found = true
if node:parent():equal(enclosing_form) then
table.insert(pairwise_nodes, node)
if node:equal(target_node) then
found = true
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions tests/nvim-paredit/pair_drag_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ describe("pair dragging ::", function()
})
end)

it("should stop dragging at pair boundaries", function()
prepare_buffer({
"{:entity {|:a 1 :b 2}}",
})
paredit.drag_element_backwards({
dragging = {
auto_drag_pairs = true,
},
})
expect({
"{:entity {|:a 1 :b 2}}",
})
end)

it("should detect various types", function()
expect_all(function()
paredit.drag_element_forwards({ dragging = { auto_drag_pairs = true } })
Expand Down

0 comments on commit 3db0850

Please sign in to comment.