Skip to content

Commit

Permalink
fix(cmdline): dont restore cursor after render. Fixes #959
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 5, 2024
1 parent d9991ca commit c49a4b0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
10 changes: 1 addition & 9 deletions lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,7 @@ function M.fix_cursor()
if not win or not M.real_cursor then
return
end
local cursor = { vim.api.nvim_buf_line_count(M.position.buf), M.position.cursor }
vim.api.nvim_win_set_cursor(win, cursor)
local leftcol = math.max(cursor[2] - vim.api.nvim_win_get_width(win) + 1, 0)
local view = vim.api.nvim_win_call(win, vim.fn.winsaveview)
if view.leftcol ~= leftcol then
vim.api.nvim_win_call(win, function()
vim.fn.winrestview({ leftcol = leftcol })
end)
end
vim.api.nvim_win_set_cursor(win, { vim.api.nvim_buf_line_count(M.position.buf), M.position.cursor })
vim.api.nvim__redraw({ cursor = true, win = win, flush = true })
end

Expand Down
12 changes: 0 additions & 12 deletions lua/noice/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,6 @@ function View:render(buf, opts)
vim.api.nvim_buf_clear_namespace(buf, Config.ns, linenr - 1, -1)
Message._buf_messages[buf] = {}

---@type number?
local win = vim.fn.bufwinid(buf)
if win == -1 then
win = nil
end
local cursor = win and vim.api.nvim_win_get_cursor(win)

if not opts.highlight then
vim.api.nvim_buf_set_lines(buf, linenr - 1, -1, false, {})
end
Expand All @@ -284,11 +277,6 @@ function View:render(buf, opts)
end
linenr = linenr + m:height()
end

if cursor then
-- restore cursor
pcall(vim.api.nvim_win_set_cursor, win, cursor)
end
end

return View

0 comments on commit c49a4b0

Please sign in to comment.