Skip to content

Commit

Permalink
fix(hop): fix range check across lines
Browse files Browse the repository at this point in the history
  • Loading branch information
champignoom committed Dec 20, 2023
1 parent baaf13a commit 70d5c6a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ module.config.public = {
external_filetypes = {},
}

local function xy_le(x0, y0, x1, y1)
return x0 < x1 or (x0 == x1 and y0 <= y1)
end

local function range_contains(r_out, r_in)
return
xy_le(r_out.row_start, r_out.column_start, r_in.row_start, r_in.column_start)
and xy_le(r_in.row_end, r_in.column_end, r_out.row_end, r_out.column_end)
end

---@class core.esupports.hop
module.public = {
--- Follow link from a specific node
Expand Down Expand Up @@ -455,11 +465,7 @@ module.public = {

-- Check whether the node captured node is in bounds.
-- There are certain rare cases where incorrect nodes would be parsed.
if
capture_node_range.row_start >= range.row_start
and capture_node_range.row_end <= capture_node_range.row_end
and capture_node_range.column_start >= range.column_start
and capture_node_range.column_end <= range.column_end
if range_contains(range, capture_node_range)
then
local extract_node_text = lib.wrap(module.required["core.integrations.treesitter"].get_node_text, node)

Expand Down

0 comments on commit 70d5c6a

Please sign in to comment.