mirror of
https://github.com/neovim/neovim.git
synced 2026-08-04 14:48:45 +00:00
fix(treesitter): select with node ending with unicode char (#38557)
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
(cherry picked from commit 1bcf2d7f90)
This commit is contained in:
committed by
github-actions[bot]
parent
b2702913b9
commit
2d9619fac7
@@ -381,14 +381,17 @@ local function get_selection()
|
|||||||
--- @type Range4,Range4
|
--- @type Range4,Range4
|
||||||
pos1, pos2 = pos2, pos1
|
pos1, pos2 = pos2, pos1
|
||||||
end
|
end
|
||||||
local range = { pos1[2] - 1, pos1[3] - 1, pos2[2] - 1, pos2[3] }
|
|
||||||
|
|
||||||
if range[4] == #vim.fn.getline(range[3] + 1) + 1 then
|
if pos2[3] == #vim.fn.getline(pos2[2]) + 1 then
|
||||||
range[3] = range[3] + 1
|
pos2[2] = pos2[2] + 1
|
||||||
range[4] = 0
|
pos2[3] = 0
|
||||||
|
else
|
||||||
|
-- set {pos2} to pos of last byte of character under {pos2} (rather than first)
|
||||||
|
local r = vim.fn.getregionpos(pos2, pos2, { exclusive = false })
|
||||||
|
pos2 = r[#r][2]
|
||||||
end
|
end
|
||||||
|
|
||||||
return range
|
return { pos1[2] - 1, pos1[3] - 1, pos2[2] - 1, pos2[3] }
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_parent_from_range(range)
|
local function get_parent_from_range(range)
|
||||||
|
|||||||
@@ -176,6 +176,21 @@ describe('treesitter incremental-selection', function()
|
|||||||
treeselect('select_parent')
|
treeselect('select_parent')
|
||||||
eq('foo(1)\nbar(2)\n', get_selected())
|
eq('foo(1)\nbar(2)\n', get_selected())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('handles unicode', function()
|
||||||
|
set_lines {
|
||||||
|
'',
|
||||||
|
'foo("abö")',
|
||||||
|
'',
|
||||||
|
}
|
||||||
|
|
||||||
|
feed('gg', 'jfb', 'v')
|
||||||
|
treeselect('select_node')
|
||||||
|
eq('abö', get_selected())
|
||||||
|
|
||||||
|
treeselect('select_parent')
|
||||||
|
eq('"abö"', get_selected())
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('treesitter incremental-selection with injections', function()
|
describe('treesitter incremental-selection with injections', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user