Iron-E / nvim-libmodal

Create new "modes" for Neovim!
Other
118 stars 7 forks source link

`CursorMoved` / `CursorMovedI` isn't triggered inside custom mode #31

Closed mawkler closed 8 months ago

mawkler commented 8 months ago

To reproduce:

M.mode = {
  k = function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) end,
  j = function() vim.api.nvim_win_set_cursor(0, { 2, 0 }) end,
}

vim.keymap.set('n', 'M', function()
  vim.api.nvim_create_autocmd('CursorMoved', {
    callback = function()
      vim.notify('Cursor moved')
    end,
  })

  require('libmodal').mode.enter('Mode', M.mode)
end)
  1. Press M to enter custom mode
  2. Press k/j a couple of times (notice that no notification is sent from the autocmd)
  3. Press <esc> to leave mode
  4. Press k/j: now the notification is sent
Iron-E commented 8 months ago

This seems specific to the CursorMoved event, I tried it with other events and couldn't reproduce. For example:

local M = {}

M.mode = {
  k = 'e foo',
  j = 'e bar',
}

vim.keymap.set('n', 'M', function()
  local id = vim.api.nvim_create_autocmd('BufNew', {
    callback = function()
      vim.notify('Cursor moved')
    end,
  })

  require('libmodal').mode.enter('Mode', M.mode)

  vim.api.nvim_del_autocmd(id)
end)

The special case for CursorMoved (and I imagine CursorMovedI as well) seems caused by the Neovim issue mentioned in #27.

Edit: to fix this CursorMoved can be manually sent out as appropriate.

mawkler commented 8 months ago

Ok!

Iron-E commented 8 months ago

These events should automatically work as expected now

mawkler commented 8 months ago

Works great, thank you very much!