Skip to content

Commit

Permalink
fix: cursor sometimes disappears after making changes (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jul 4, 2024
1 parent b15e4c1 commit b5a1abf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lua/oil/mutator/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions lua/oil/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b5a1abf

Please sign in to comment.