diff options
-rw-r--r-- | runtime/lua/vim/snippet.lua | 7 | ||||
-rw-r--r-- | test/functional/lua/snippet_spec.lua | 4 |
2 files changed, 5 insertions, 6 deletions
diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua index 2edea6d5ad..6d572fed34 100644 --- a/runtime/lua/vim/snippet.lua +++ b/runtime/lua/vim/snippet.lua @@ -420,6 +420,7 @@ end function M.expand(input) local snippet = G.parse(input) local snippet_text = {} + ---@type string local base_indent = vim.api.nvim_get_current_line():match('^%s*') or '' -- Get the placeholders we should use for each tabstop index. @@ -454,12 +455,6 @@ function M.expand(input) --- --- @param text string|string[] local function append_to_snippet(text) - 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 - end - local shiftwidth = vim.fn.shiftwidth() local curbuf = vim.api.nvim_get_current_buf() local expandtab = vim.bo[curbuf].expandtab diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua index be18fe7898..724437f0b2 100644 --- a/test/functional/lua/snippet_spec.lua +++ b/test/functional/lua/snippet_spec.lua @@ -79,6 +79,10 @@ describe('vim.snippet', function() -- Regression test: #29658 api.nvim_buf_set_lines(curbuf, 0, -1, false, {}) test_expand_success({ '${1:foo^bar}\n' }, { 'foo^bar', '' }) + + -- Regression test: #30950 + api.nvim_buf_set_lines(curbuf, 0, -1, false, {}) + test_expand_success({ 'a^ b$1', 'b$2', 'd' }, { 'a^ b', 'b', 'd' }) end) it('replaces tabs with spaces when expandtab is set', function() |