From 424f4cc0389ed883f220bd5cbab9c07b4955acde Mon Sep 17 00:00:00 2001 From: Avinash Thakur <19588421+80avin@users.noreply.github.com> Date: Wed, 19 Mar 2025 20:17:59 +0530 Subject: fix(snippet): wrong indentation when snippet contains "^" #32970 ## Problem The pattern used to match indentation is wrong as can be seen in ```lua -- current pattern doesn't match starting space print(vim.inspect((" xyz"):match("(^%s+)%S"))) -- nil -- instead, it matches characters `^ ` in text print(vim.inspect(("x^ yz"):match("(^%s+)%S"))) -- "^ " -- indentation could've been matched by, however not required print(vim.inspect((" xyz"):match("^(%s+)%S"))) -- " " ``` ## Solution We don't even need to modify `base_indent` at every line. If every line's indentation is calculated by the previous line's indentation (which already has starting indentation) added to the starting indentation, we see that indentation is multiplied on every line. Hence, we only add the starting line indentation to every line. --- test/functional/lua/snippet_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/lua') 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() -- cgit