fix(snippet): setting end_right_gravity (#35061)

When right_gravity is set to true for deactivating tabstop expansion we
have to set end_right_gravity to false to avoid expanding the tabstop
region on the right side. Vice versa for activating tabstop expansion
again.
This commit is contained in:
TheBlob42
2025-07-27 21:19:01 +02:00
committed by GitHub
parent afebbd0f34
commit dff78f580d
2 changed files with 7 additions and 3 deletions

View File

@@ -119,7 +119,7 @@ local Tabstop = {}
function Tabstop.new(index, bufnr, range, choices)
local extmark_id = vim.api.nvim_buf_set_extmark(bufnr, snippet_ns, range[1], range[2], {
right_gravity = true,
end_right_gravity = true,
end_right_gravity = false,
end_line = range[3],
end_col = range[4],
hl_group = hl_group,
@@ -170,7 +170,7 @@ function Tabstop:set_right_gravity(right_gravity)
local range = self:get_range()
self.extmark_id = vim.api.nvim_buf_set_extmark(self.bufnr, snippet_ns, range[1], range[2], {
right_gravity = right_gravity,
end_right_gravity = true,
end_right_gravity = not right_gravity,
end_line = range[3],
end_col = range[4],
hl_group = hl_group,

View File

@@ -249,7 +249,11 @@ describe('vim.snippet', function()
feed('<Tab>')
poke_eventloop()
feed(',2')
eq({ 'for i=1,10,2 do', '\t', 'end' }, buf_lines(0))
-- Make sure changes on previous tabstops does not change following ones
feed('<S-Tab>')
poke_eventloop()
feed('20')
eq({ 'for i=1,20,2 do', '\t', 'end' }, buf_lines(0))
end)
it('updates snippet state when built-in completion menu is visible', function()