fix(snippet): modify base indentation when there's actually whitespace (#29670)

This commit is contained in:
Maria José Solano 2024-07-16 10:30:22 -07:00 committed by GitHub
parent 118ae7e5ed
commit 5fe4ce6678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -514,7 +514,7 @@ function M.expand(input)
local snippet_lines = text_to_lines(snippet_text)
-- Get the base indentation based on the current line and the last line of the snippet.
if #snippet_lines > 0 then
base_indent = base_indent .. (snippet_lines[#snippet_lines]:match('(^%s*)%S') or '') --- @type string
base_indent = base_indent .. (snippet_lines[#snippet_lines]:match('(^%s+)%S') or '') --- @type string
end
local shiftwidth = vim.fn.shiftwidth()

View File

@ -58,7 +58,13 @@ describe('vim.snippet', function()
end)
it('adds indentation based on the start of snippet lines', function()
local curbuf = api.nvim_get_current_buf()
test_expand_success({ 'if $1 then', ' $0', 'end' }, { 'if then', ' ', 'end' })
-- Regression test: #29658
api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
test_expand_success({ '${1:foo^bar}\n' }, { 'foo^bar', '' })
end)
it('replaces tabs with spaces when expandtab is set', function()