mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
fix: node selection at line start that ends injected region
This commit is contained in:
parent
e8c5242f53
commit
8acafab2bc
1 changed files with 18 additions and 4 deletions
|
|
@ -202,12 +202,26 @@ function M.get_root_for_position(line, col, root_lang_tree)
|
|||
|
||||
local lang_tree = root_lang_tree:language_for_range { line, col, line, col }
|
||||
|
||||
for _, tree in pairs(lang_tree:trees()) do
|
||||
local root = tree:root()
|
||||
while true do
|
||||
for _, tree in pairs(lang_tree:trees()) do
|
||||
local root = tree:root()
|
||||
|
||||
if root and ts.is_in_node_range(root, line, col) then
|
||||
return root, tree, lang_tree
|
||||
if root and ts.is_in_node_range(root, line, col) then
|
||||
return root, tree, lang_tree
|
||||
end
|
||||
end
|
||||
|
||||
if lang_tree == root_lang_tree then
|
||||
break
|
||||
end
|
||||
|
||||
-- This case can happen when the cursor is at the start of a line that ends a injected region,
|
||||
-- e.g., the first `]` in the following lua code:
|
||||
-- ```
|
||||
-- vim.cmd[[
|
||||
-- ]]
|
||||
-- ```
|
||||
lang_tree = lang_tree:parent() -- NOTE: parent() method is private
|
||||
end
|
||||
|
||||
-- This isn't a likely scenario, since the position must belong to a tree somewhere.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue