LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

Highlight for "zero-width" placeholder

Open gruvw opened this issue 2 years ago • 4 comments

Hello, thanks for the awesome plugin!

I am trying to get a visual indication of the unvisited placeholders when expanding a snippet.

So far I was able to achieve this but only for placeholders/tabstops that had a default "non-zero-width" content:

vim.api.nvim_set_hl(0, 'LuaSnipPlace', { bg = "#363537", italic = true })

local types = require("luasnip.util.types")

require("luasnip").setup({
  ext_opts = {
    [types.insertNode] = {
      unvisited = {
        hl_group = "LuaSnipPlace",
      },
    },
    [types.exitNode] = {
      unvisited = {
        hl_group = "LuaSnipPlace",
      },
    },
  }
})

However, I don't know how to get some visual lighter background on the next character for a zero-width placeholder.

Thanks a lot.

gruvw avatar Aug 23 '23 09:08 gruvw

Hi! #935 should have everything you need for this, as long as you neovim is new enough to support inline virtual text

L3MON4D3 avatar Aug 23 '23 10:08 L3MON4D3

Yes I already came across #935 which allowed me to write the current highlight config (see above).

However, I don't want virtual text, I would just want the background color of the next character to be lighter. It would give the impression that a block cursor is pending at that place. Is this possible ?

gruvw avatar Aug 23 '23 10:08 gruvw

Ouh, not as easily: you'd need to find, after each jump (:h luasnip-events), the target of the next one (ls.next_node, or something like that), get its position (node:get_buf_position, or something like that) and place an extmark just behind it (nvim_buf_set_extmark). Also, remove the mark placed for this node, so you'd have to store the id of the placed extmark. It's probably not that hard concept-wise, but finding all the right API is

L3MON4D3 avatar Aug 23 '23 11:08 L3MON4D3

Yes this sounds pretty hard to find...

gruvw avatar Aug 24 '23 12:08 gruvw