fix: cursor sometimes disappears after making changes (#438)

This commit is contained in:
Steven Arcangeli 2024-07-03 18:14:52 -07:00
parent b15e4c1e64
commit b5a1abfde0
2 changed files with 16 additions and 7 deletions

View file

@ -114,10 +114,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
render_lines(winid, bufnr, lines)
-- Disable cursor
-- We are in the preview window now, so no need to use autocmd with WinEnter
vim.api.nvim_set_hl(0, "OilPreviewCursor", { nocombine = true, blend = 100 })
vim.opt.guicursor:append("a:OilPreviewCursor/OilPreviewCursor")
local restore_cursor = util.hide_cursor()
-- Attach autocmds and keymaps
local cancel
@ -132,9 +129,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
end
autocmds = {}
vim.api.nvim_win_close(winid, true)
-- restore cursor
vim.api.nvim_set_hl(0, "OilPreviewCursor", {})
vim.opt.guicursor:remove("a:OilPreviewCursor/OilPreviewCursor")
restore_cursor()
cb(value)
end
end

View file

@ -665,6 +665,20 @@ M.get_preview_win = function()
end
end
---@return fun() restore Function that restores the cursor
M.hide_cursor = function()
vim.api.nvim_set_hl(0, "OilPreviewCursor", { nocombine = true, blend = 100 })
local original_guicursor = vim.go.guicursor
vim.go.guicursor = "a:OilPreviewCursor/OilPreviewCursor"
return function()
-- HACK: see https://github.com/neovim/neovim/issues/21018
vim.go.guicursor = "a:"
vim.cmd.redrawstatus()
vim.go.guicursor = original_guicursor
end
end
---@param bufnr integer
---@param preferred_win nil|integer
---@return nil|integer