Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions lua/nvim-treesitter-textobjects/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function M.find_best_range(bufnr, capture_string, query_group, filter_predicate,
return best
end

-- TODO: replace with `vim.Range:has(vim.Pos)` when we drop support for nvim 0.11
---@param range Range4
---@param row integer
---@param col integer
Expand All @@ -231,11 +232,18 @@ local function is_in_range(range, row, col)
return is_in_rows and is_after_start_col_if_needed and is_before_end_col_if_needed
end

---@param range1 Range4
---@param range2 Range4
-- TODO: replace with `vim.Range:has(vim.Range)` when we drop support for 0.11
---@param outer Range4
---@param inner Range4
---@return boolean
local function contains(range1, range2)
return is_in_range(range1, range2[1], range2[2]) and is_in_range(range1, range2[3], range2[4])
local function contains(outer, inner)
local start_row_o, start_col_o, end_row_o, end_col_o = unpack(outer) ---@type integer, integer, integer, integer
local start_row_i, start_col_i, end_row_i, end_col_i = unpack(inner) ---@type integer, integer, integer, integer

return start_row_o <= start_row_i
and start_col_o <= start_col_i
and end_row_o >= end_row_i
and end_col_o >= end_col_i
end

---@param range Range6
Expand Down
2 changes: 2 additions & 0 deletions tests/select/python/selection_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ def __init__(self, *arg):
my_list.append(arg_)

self.my_list = my_list

str.join(' ', map(lambda x: x + x, ['foo', 'bar', 'baz']))
3 changes: 3 additions & 0 deletions tests/select/python_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('command equality Python:', function()
run:compare_cmds('aligned_indent.py', { row = 1, col = 0, cmds = { 'dfn', 'd;' } })
-- select using move
run:compare_cmds('aligned_indent.py', { row = 1, col = 0, cmds = { 'd]a', 'v]ad', 'c]a' } })

-- test correct @parameter.inner scoping
run:compare_cmds('selection_mode.py', { row = 10, col = 22, cmds = { 'dia', 'df)' } })
run:compare_cmds(
'selection_mode.py',
{ row = 2, col = 4, cmds = { 'dam', 'dVam', 'vamd', 'Vamd' } }
Expand Down