norcalli / snippets.nvim

GNU General Public License v3.0
277 stars 13 forks source link

floaty ux keymap hardcoded? #9

Open rafcamlet opened 4 years ago

rafcamlet commented 4 years ago

It seems to floaty ux has its keymaps hardcoded. It's quite unexpected, especally if you have mapped <c-j> as advence(1) and after expand it change into advence(-1).

https://github.com/norcalli/snippets.nvim/blob/663029663e0681c49e71f18ec81650c650e7c7aa/lua/snippets/inserters/floaty.lua#L316:L320

salkin-mada commented 3 years ago

Hi @rafcamlet . I use the floaty inserter. And the expand/advance triggers (both 1 and -1) is being remapped just fine.

function M.snippets()
    local opts = { noremap = true }
    api.nvim_set_keymap('i', '<A-k>', '<cmd>lua return require"snippets".expand_or_advance(1)<CR><ESC>gH', opts)
    api.nvim_set_keymap('i', '<A-j>', '<cmd>lua return require"snippets".advance_snippet(-1)<CR><ESC>gH', opts)
    api.nvim_set_keymap('n', '<A-k>', '<cmd>lua return require"snippets".expand_or_advance(1)<CR>gH', opts)
    api.nvim_set_keymap('n', '<A-j>', '<cmd>lua return require"snippets".advance_snippet(-1)<CR>gH', opts)
    api.nvim_set_keymap('s', '<A-k>', '<cmd>lua return require"snippets".expand_or_advance(1)<CR><ESC>gH', opts)
    api.nvim_set_keymap('s', '<A-j>', '<cmd>lua return require"snippets".advance_snippet(-1)<CR><ESC>gH', opts)
end
rafcamlet commented 3 years ago

@salkin-mada There are hardcoded mappings in floaty ux buffer, which overwrites my custom mappings. https://github.com/norcalli/snippets.nvim/blob/663029663e0681c49e71f18ec81650c650e7c7aa/lua/snippets/inserters/floaty.lua#L316:L320

    api.nvim_buf_set_keymap(input_buf, 'i', '<c-k>', '<Cmd>lua SNIPPETS_FLOATY_HANDLER(1)<cr>', { noremap = true; silent = true })
    api.nvim_buf_set_keymap(input_buf, 'i', '<c-j>', '<Cmd>lua SNIPPETS_FLOATY_HANDLER(-1)<cr>', { noremap = true; silent = true })

I'm using inoremap <c-j> <cmd>lua return require'snippets'.expand_or_advance(1)<CR> but inside floaty buffer it is changed to lua SNIPPETS_FLOATY_HANDLER(-1) which is wrapper for require'snippets'.advance_snippet, but it has opposite sign.

aoswalt commented 3 years ago

As a workaround, I was able to override the advance_snippet function to flip the sign.

local M = require'snippets'
local orig_advance = M.advance_snippet
local advance = function(offset)
  offset = offset or 1
  orig_advance(-offset)
end
M.advance_snippet = advance