quangnguyen30192 / cmp-nvim-ultisnips

nvim-cmp source for ultisnips
Apache License 2.0
144 stars 19 forks source link

Using tab to jump forward leaves a space before jumping forward #74

Closed medwatt closed 2 years ago

medwatt commented 2 years ago

The relevant part of my config is given below along with a screen recording. I currently have Tab mapped to just jump forward. When I'm inside a snippet and the completion menu pops up, pressing Tab does not automatically jump to the next place holder. Instead, it inserts a space. It's only after that that I can jump forward.


["<Tab>"] = cmp.mapping(
    function(fallback)
        cmp_ultisnips_mappings.compose {"jump_forwards"}(fallback)
    end, {"i", "s"}),

["<S-Tab>"] = cmp.mapping(
    function(fallback)
        cmp_ultisnips_mappings.compose {"jump_backwards"}(fallback)
    end, {"i", "s"}),

nvim

quangnguyen30192 commented 2 years ago

Can you give us your minimal current config?

quangnguyen30192 commented 2 years ago

I could reproduce the issue, working on it

smjonas commented 2 years ago

Thanks for reporting, it should be fixed now :)

quangnguyen30192 commented 2 years ago

Hey @smjonas I think he wanted to press <TAB> confirm the selected entry and then <tab> to jump to the next stop

quangnguyen30192 commented 2 years ago

If mapping the confirm behavior to a different key then it's fine. But it would be more flexible if we introduce confirm mapping in the compose then the user could combine it with whatever he wants. E.g

local function has_item_selected()
  return cmp.visible() and cmp.get_selected_entry() ~= nil
end

-- The <Plug> mappings are defined in autoload/cmp_nvim_ultisnips.vim.

local actions = {
   .....
   select_item = {
    condition = { has_item_selected },
    command = { cmp.confirm }
  }
  ....
}

Then in user mapping

["<Tab>"] = cmp.mapping(
    function(fallback)
        cmp_ultisnips_mappings.compose {"select_item", "jump_forwards"}(fallback)
    end, {"i", "s"}),
smjonas commented 2 years ago

@quangnguyen30192 That seems like a good idea. Maybe we can let users override the actions table like

mappings = {
    actions = { ... }
}

But as I understand it, the original issue was still solved by the PR, right? Any comments, @medwatt?