Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shared) better inner parameter selection #702

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions lua/nvim-treesitter-textobjects/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,24 @@ end
---@param range Range4
---@param row integer
---@param col integer
---@param end_col_offset integer?
---@return boolean
local function is_in_range(range, row, col)
local function is_in_range(range, row, col, end_col_offset)
local start_row, start_col, end_row, end_col = unpack(range) ---@type integer, integer, integer, integer
end_col = end_col - 1

local is_in_rows = start_row <= row and end_row >= row
local is_after_start_col_if_needed = true
if start_row == row then
is_after_start_col_if_needed = col >= start_col
if start_row > row or end_row < row then
return false
end
local is_before_end_col_if_needed = true
if end_row == row then
is_before_end_col_if_needed = col <= end_col

if start_row ~= row or col < start_col then
return false
end
return is_in_rows and is_after_start_col_if_needed and is_before_end_col_if_needed

if end_row ~= row then
return true
end

return col <= end_col + (end_col_offset or 0)
end

---@param range1 Range4
Expand Down Expand Up @@ -276,7 +279,7 @@ local function best_range_at_point(ranges, row, col, opts)
local lookbehind_earliest_start ---@type integer

for _, range in pairs(ranges) do
if range and is_in_range(M.torange4(range), row, col) then
if range and is_in_range(M.torange4(range), row, col, -1) then
local length = range[6] - range[3]
if not range_length or length < range_length then
smallest_range = range
Expand Down
Loading