mei28 / luminate.nvim

🌟 Highlight yanked, pasted, and undone/redone text in Neovim with a splash of color.
MIT License
38 stars 2 forks source link

Address #8 and #15 #22

Open JayLCypher opened 1 month ago

JayLCypher commented 1 month ago

Alternative to the description, the string can be "which_key_ignore", which will make it not pop up in Which_Key plugin.

Issue: It seems that the 'o' and 'O' keymaps (that append or prepend a new line and enters insert mode) calls to the event for highlighting with the event_type "undo". No idea why. Please try it out before merging. I did remap the put key "p" to test, and it preserves the original description, as well as provide pasting with register interaction like it's supposed to.

map("n", "u", "u <cmd>print<CR>")
map("n", "p", "p <cmd>print<CR>", { desc = "lamo gotem"})

Furthermore we should probably advocate for TextPutPost, TextUndoPost and TextRedoPost autocommands provided by Neovim, inline with TextYankPost for better highlighting support. :)

mei28 commented 1 month ago

Thank you for your PR. When I tested it, I found the same problem as #7.

I am considering how to address this issue.

JayLCypher commented 1 month ago

Yeah I noticed that too. Seems like the first paste + some lazy-loading of autocommands or buffer changes that affects when the plugin is initialized or something. Don't think it's related to lazy since I've tried VimEnter, BufEnter and lazy = false, and all behavior is the same.

I suspect there are some quirks I'm not aware of, but for now I at least have register put/paste-ing :)

mei28 commented 1 month ago

I found that when I added the function, the issue of it not working the first time was resolved.

I'm not sure why this solution works or if it’s the best approach. What do you think?

  if config_module.config.paste.enabled then
    M.attach_bytes_highlight('paste') -- add this code
    api.nvim_create_autocmd('User', {
      pattern = { 'Luminate_paste' },
      group = 'LuminateHighlight',
      callback = function() M.attach_bytes_highlight('paste') end
    })
  end

  if config_module.config.undo.enabled then
    M.attach_bytes_highlight('undo')  -- add this code
    api.nvim_create_autocmd('User', {
      pattern = { 'Luminate_undo' },
      group = 'LuminateHighlight',
      callback = function() M.attach_bytes_highlight('undo') end
    })
  end

  if config_module.config.redo.enabled then
    M.attach_bytes_highlight('redo')  -- add this code
    api.nvim_create_autocmd('User', {
      pattern = { 'Luminate_redo' },
      group = 'LuminateHighlight',
      callback = function() M.attach_bytes_highlight('redo') end
    })
  end
JayLCypher commented 1 month ago

Good thing you didn't merge this, I see now how this works and the flaws of the implementation. Turns out I had no idea what I was doing. :⁾

Just to describe what's happening:

This is sub-optimal. We need some way to differentiate what dispatch to send based on event. The connection to buffer text change needs to be on event, rather than registered all of the time, especially if we want to support pasting in Insert mode eventually. The buffer attachment needs to happen before the changedtick event happens, so that we get the correct columns and rows.

I'm not sure what a good way to do this is yet, an on_key() handler to put a callback on the p, and u keys seems silly, since the keys can change. We'd want to be config-agnostic. I need to think.