Use isn for visual selection indentations.

main
Joshua Potter 2024-01-05 08:45:33 -07:00
parent 288ed2d452
commit 60a48b8186
2 changed files with 16 additions and 13 deletions

View File

@ -47,7 +47,7 @@ for {} in {}:
})[index])
)
end, { 1 }),
ul.visual_node,
ul.visual_dynamic_node(3),
}
)
),

View File

@ -2,19 +2,17 @@ local M = {}
local luasnip = require('luasnip')
local types = require('luasnip.util.types')
local function_node = require('luasnip').function_node
M.visual_node = function_node(function(_, snip)
local env = snip.env
if type(env.LS_SELECT_RAW) ~= 'table' then
return env.LS_SELECT_RAW
function M.visual_dynamic_node(pos)
local f = luasnip.function_node
local isn = luasnip.indent_snippet_node
return isn(pos, {
f(function(_, parent)
return parent.snippet.env.LS_SELECT_DEDENT or {}
end)
}, '$PARENT_INDENT\t')
end
local res = {}
for _, ele in ipairs(env.LS_SELECT_RAW) do
table.insert(res, ele)
end
return res
end, {})
function M.choice_index(choice_node)
for i, c in ipairs(choice_node.choices) do
@ -46,6 +44,11 @@ function M.setup()
},
}
-- Track where we are expanding the snippet.
luasnip.env_namespace('INFO', {
init = function(info) return { POS = info.pos } end,
})
vim.keymap.set({ 'i', 's' }, '<c-e>', function()
if luasnip.choice_active() then
return '<Plug>luasnip-next-choice'