Skip to content

Commit b5a1abf

Browse files
committed
fix: cursor sometimes disappears after making changes (#438)
1 parent b15e4c1 commit b5a1abf

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lua/oil/mutator/preview.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
114114

115115
render_lines(winid, bufnr, lines)
116116

117-
-- Disable cursor
118-
-- We are in the preview window now, so no need to use autocmd with WinEnter
119-
vim.api.nvim_set_hl(0, "OilPreviewCursor", { nocombine = true, blend = 100 })
120-
vim.opt.guicursor:append("a:OilPreviewCursor/OilPreviewCursor")
117+
local restore_cursor = util.hide_cursor()
121118

122119
-- Attach autocmds and keymaps
123120
local cancel
@@ -132,9 +129,7 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
132129
end
133130
autocmds = {}
134131
vim.api.nvim_win_close(winid, true)
135-
-- restore cursor
136-
vim.api.nvim_set_hl(0, "OilPreviewCursor", {})
137-
vim.opt.guicursor:remove("a:OilPreviewCursor/OilPreviewCursor")
132+
restore_cursor()
138133
cb(value)
139134
end
140135
end

lua/oil/util.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,20 @@ M.get_preview_win = function()
665665
end
666666
end
667667

668+
---@return fun() restore Function that restores the cursor
669+
M.hide_cursor = function()
670+
vim.api.nvim_set_hl(0, "OilPreviewCursor", { nocombine = true, blend = 100 })
671+
local original_guicursor = vim.go.guicursor
672+
vim.go.guicursor = "a:OilPreviewCursor/OilPreviewCursor"
673+
674+
return function()
675+
-- HACK: see https://github.com/neovim/neovim/issues/21018
676+
vim.go.guicursor = "a:"
677+
vim.cmd.redrawstatus()
678+
vim.go.guicursor = original_guicursor
679+
end
680+
end
681+
668682
---@param bufnr integer
669683
---@param preferred_win nil|integer
670684
---@return nil|integer

0 commit comments

Comments
 (0)