How can I check if matching trigger is already expanded? #1185
-
I want to implement autopair functionality with luasnip. e.g.
As I’ve already expanded & closed the To do that, I want to check if cursor is at 0th jump index of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Mhmm, we don't really have a reliable api for the general case (for any cursor-position, find whether it is immediately behind some active snippet), but for this specific case where you've just jumped to the $0, you can get the trigger of the snippet before the cursor, and whether you've just jumped to the $0 local current_node = require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
local current_snippet_trigger = current_node.parent.snippet.trigger
local current_is_0 = current_node.pos == 0 (maybe, also check whether the cursor is actually still on the $0, get the position via |
Beta Was this translation helpful? Give feedback.
Mhmm, we don't really have a reliable api for the general case (for any cursor-position, find whether it is immediately behind some active snippet), but for this specific case where you've just jumped to the $0, you can get the trigger of the snippet before the cursor, and whether you've just jumped to the $0
(maybe, also check whether the cursor is actually still on the $0, get the position via
current_node:get_buf_position()
, and check it against the position of the cursor (beware of 0…