Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmdline): check cursor position to avoid hang on exit #936

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,15 @@ 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 }

local line_count = vim.api.nvim_buf_line_count(M.position.buf)
local cursor_line = math.min(line_count, M.position.cursor)
local cursor = { cursor_line, M.position.cursor }

if cursor[1] < 1 or cursor[1] > line_count or cursor[2] < 0 then
return -- Exit if cursor position is invalid
end

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)
Expand Down