norcalli / nvim-colorizer.lua

The fastest Neovim colorizer.
Other
2.19k stars 115 forks source link

Cursor color #1

Open doronbehar opened 4 years ago

doronbehar commented 4 years ago

Hi!

I just came around your plugin via your reddit post (I think it's yours) and I have a question:

Say I have the color #FFFFFF. When the cursor hovers on this text, I can't see it. Would it be possible to make nvim-colorizer.lua change the highlighting groups nCursor and / or Cursor so the cursor will be visible in such edge cases?

norcalli commented 4 years ago

Thanks for the issue! I'll look into it to see how it affects the performance since it would have to update on CursorMoved based on what you're suggesting, which could potentially be slow. Considering that, I could probably put it under an optional configuration setting which you could set under the defaults if you really like it.

norcalli commented 4 years ago

I figured out a way to do this, so I'm going to write it here for my future reference when I get around to it (since I'm busy today).

The mechanism for doing this with neovim doesn't exist right now to get the highlight under the cursor, so I'll have to maintain a memory of the highlight regions.

I can maintain a single global table containing the highlight regions in order and do a binary search of list to find the cursors position (or a linear search, the performance will probably be negligible in difference), then I can ascertain the highlight under the cursor if a match is found.

With an autocmd on CursorMove, I'll only need to calculate this array if the line number changes or the text changes, and not the column number, so it'll involve recalculating the current row, but with how quick that is, I don't think the performance will be a problem.

If the buffer changes, this will also need to be invalidated/updated, which may or may not be covered by CursorMove.

norcalli commented 4 years ago

Implemented in #16, but unfortunately, I don't have a good way of testing this. Cursor color isn't a standardized terminal feature, and GUIs can implement it however they want. I recommend trying that branch if your terminal supports it and let me know if it works.