Skip to content

Commit 48007d6

Browse files
committed
fixup! fix: range containment check (e.g. weird @parameter.inner behavior) (#840)
1 parent e91c585 commit 48007d6

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

lua/nvim-treesitter-textobjects/shared.lua

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -217,33 +217,15 @@ end
217217
---@param col integer
218218
---@return boolean
219219
local function is_in_range(range, row, col)
220-
local start_row, start_col, end_row, end_col = unpack(range) ---@type integer, integer, integer, integer
221-
end_col = end_col - 1
222-
223-
local is_in_rows = start_row <= row and end_row >= row
224-
local is_after_start_col_if_needed = true
225-
if start_row == row then
226-
is_after_start_col_if_needed = col >= start_col
227-
end
228-
local is_before_end_col_if_needed = true
229-
if end_row == row then
230-
is_before_end_col_if_needed = col <= end_col
231-
end
232-
return is_in_rows and is_after_start_col_if_needed and is_before_end_col_if_needed
220+
return ts._range.contains(range, { row, col, row, col + 1 })
233221
end
234222

235223
-- TODO: replace with `vim.Range:has(vim.Range)` when we drop support for 0.11
236224
---@param outer Range4
237225
---@param inner Range4
238226
---@return boolean
239227
local function contains(outer, inner)
240-
local start_row_o, start_col_o, end_row_o, end_col_o = unpack(outer) ---@type integer, integer, integer, integer
241-
local start_row_i, start_col_i, end_row_i, end_col_i = unpack(inner) ---@type integer, integer, integer, integer
242-
243-
return start_row_o <= start_row_i
244-
and start_col_o <= start_col_i
245-
and end_row_o >= end_row_i
246-
and end_col_o >= end_col_i
228+
return ts._range.contains(outer, inner)
247229
end
248230

249231
---@param range Range6
@@ -274,7 +256,8 @@ local function best_range_at_point(ranges, row, col, opts)
274256
local lookbehind_earliest_start ---@type integer
275257

276258
for _, range in pairs(ranges) do
277-
if range and is_in_range(M.torange4(range), row, col) then
259+
local range4 = M.torange4(range)
260+
if range and is_in_range(range4, row, col) then
278261
local length = range[6] - range[3]
279262
if not range_length or length < range_length then
280263
smallest_range = range

0 commit comments

Comments
 (0)