echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.83k stars 181 forks source link

Maybe a better way to hide cursor #1087

Closed lostl1ght closed 3 weeks ago

lostl1ght commented 1 month ago

Contributing guidelines

Module(s)

mini.pick

Description

Hello!

Some while ago I posted in discussions how I change cursor shape with :h guicursor so that it looks better when using 'noice.nvim'.

Apparently, hi' groups have a parameter named blend and hi' groups can be used in guicursor.

Below is a snippet that can be used to hide cursor. It works with and without 'noice.nvim' and with it cursor does not jump around the window. So maybe this is what 'mini.pick' should do instead of putting cursor in cmdline.

Snippet ```lua vim.api.nvim_set_hl(0, 'MiniPickHiddenCursor', { blend = 100, nocombine = true }) local guicursor local group = vim.api.nvim_create_augroup('MiniPickHideCursor', {}) vim.api.nvim_create_autocmd('User', { pattern = 'MiniPickStart', callback = function() if guicursor == nil then guicursor = vim.go.guicursor end vim.schedule(function() if guicursor then vim.go.guicursor = 'a:MiniPickHiddenCursor' end end) end, group = group, }) vim.api.nvim_create_autocmd('User', { pattern = 'MiniPickStop', callback = function() if guicursor then vim.schedule(function() if guicursor then vim.go.guicursor = guicursor guicursor = nil end end) end end, group = group, }) ```
echasnovski commented 1 month ago

Thanks for the suggestion!

Can you please elaborate on why is it better to avoid putting cursor in command line?

lostl1ght commented 1 month ago

It's mainly for 'neovide' and maybe for other plugins that provide visual feedback when cursor jumps. In 'neovide' there's a visual effect for when cursor jumps and it can be distracting in this particular case because cursor jumps in cmdline only to be 'hidden'. That's why I think it would be better if 'mini.pick' truly hid cursor.

lostl1ght commented 1 month ago

And 'mini.pick' would work as intended with 'noice.nvim' out of the box.

echasnovski commented 1 month ago

It's mainly for 'neovide' and maybe for other plugins that provide visual feedback when cursor jumps. In 'neovide' there's a visual effect for when cursor jumps and it can be distracting in this particular case because cursor jumps in cmdline only to be 'hidden'. That's why I think it would be better if 'mini.pick' truly hid cursor.

I see. I'll take a look, but in my experience this type of "cache and restore" is better to be avoided because if something goes wrong (in this case, MiniPickStop User event is not triggered for some reason), cursor might not get restored. And this will be a very visible (or, rather, invisible :) ) issue.

echasnovski commented 3 weeks ago

@lostl1ght, I've tested the approach directly in 'mini.pick' code instead of 'cmdheight' (i.e. without autocommands), and it seems to work really well! Thanks for pointing this out! The downside is that it requires exporting an extra highlight group, but it seems worth it.

This should now be implemented in main branch.

lostl1ght commented 2 weeks ago

Works great! Thank you!