diff --git a/lua/oil/mutator/preview.lua b/lua/oil/mutator/preview.lua index 31588af..3f8d87d 100644 --- a/lua/oil/mutator/preview.lua +++ b/lua/oil/mutator/preview.lua @@ -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 diff --git a/lua/oil/util.lua b/lua/oil/util.lua index a685b14..a1a95ab 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -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