Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mawkler opened this issue Mar 11, 2024 · 4 comments · Fixed by #32
Closed

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

mawkler opened this issue Mar 11, 2024 · 4 comments · Fixed by #32
Assignees
Labels
bug Something isn't working

Comments

@mawkler
Copy link

mawkler commented Mar 11, 2024

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
Copy link
Owner

Iron-E commented Mar 11, 2024

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.

@Iron-E Iron-E changed the title autocmd isn't triggered inside custom mode CursorMoved / CursorMovedI isn't triggered inside custom mode Mar 11, 2024
@Iron-E Iron-E added the bug Something isn't working label Mar 11, 2024
@mawkler
Copy link
Author

mawkler commented Mar 12, 2024

Ok!

@Iron-E
Copy link
Owner

Iron-E commented Mar 12, 2024

These events should automatically work as expected now

@mawkler
Copy link
Author

mawkler commented Mar 13, 2024

Works great, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants