From e6cfcaed184d4ecdc8a8638429e1bd9e1b3251dc Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Sat, 25 May 2024 10:23:05 -0700 Subject: feat(snippet): add default keymaps during snippet session --- test/functional/lua/snippet_spec.lua | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'test/functional/lua/snippet_spec.lua') diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua index 413aa93994..bca0a59cb4 100644 --- a/test/functional/lua/snippet_spec.lua +++ b/test/functional/lua/snippet_spec.lua @@ -1,3 +1,5 @@ +---@diagnostic disable: no-unknown + local t = require('test.testutil') local n = require('test.functional.testnvim')() @@ -16,11 +18,6 @@ local retry = t.retry describe('vim.snippet', function() before_each(function() clear() - - exec_lua([[ - vim.keymap.set({ 'i', 's' }, '', function() vim.snippet.jump(1) end, { buffer = true }) - vim.keymap.set({ 'i', 's' }, '', function() vim.snippet.jump(-1) end, { buffer = true }) - ]]) end) after_each(clear) @@ -286,4 +283,24 @@ describe('vim.snippet', function() ]] ) end) + + it('restores snippet navigation keymaps', function() + -- Create a buffer keymap in insert mode that deletes all lines. + local curbuf = api.nvim_get_current_buf() + exec_lua('vim.api.nvim_buf_set_keymap(..., "i", "", "normal ggdG", {})', curbuf) + + test_expand_success({ 'var $1 = $2' }, { 'var = ' }) + + -- While the snippet is active, should navigate between tabstops. + feed('x') + poke_eventloop() + feed('0') + eq({ 'var x = 0' }, buf_lines(0)) + + exec_lua('vim.snippet.stop()') + + -- After exiting the snippet, the buffer keymap should be restored. + feed('O') + eq({ '' }, buf_lines(0)) + end) end) -- cgit From 5fe4ce6678c0b531487e4d9836774464b5ec56ed Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Tue, 16 Jul 2024 10:30:22 -0700 Subject: fix(snippet): modify base indentation when there's actually whitespace (#29670) --- test/functional/lua/snippet_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/lua/snippet_spec.lua') diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua index bca0a59cb4..eb2f17216c 100644 --- a/test/functional/lua/snippet_spec.lua +++ b/test/functional/lua/snippet_spec.lua @@ -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() -- cgit