Skip to content

Conversation

Copy link

Copilot AI commented Jan 5, 2026

The chat UI crashes with "Cursor position outside buffer" when starting a new session because nvim_win_set_cursor is called with line 0 on an empty buffer.

Changes

  • Add bounds check before setting cursor position in render() to prevent invalid cursor position when buffer is empty
  • Only call nvim_win_set_cursor when #lines > 0
-- Before
if vim.api.nvim_win_is_valid(M.state.winid) then
  vim.api.nvim_win_set_cursor(M.state.winid, { #lines, 0 })
end

-- After
if vim.api.nvim_win_is_valid(M.state.winid) and #lines > 0 then
  vim.api.nvim_win_set_cursor(M.state.winid, { #lines, 0 })
end

This occurs in new_session() which clears all messages before the backend creates a new session, resulting in a 0-line buffer render.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: verlihirsh <6280012+verlihirsh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues with custom chat frontend Fix cursor position error when rendering empty chat buffer Jan 5, 2026
Copilot AI requested a review from verlihirsh January 5, 2026 14:37
@verlihirsh verlihirsh marked this pull request as ready for review January 5, 2026 14:37
@verlihirsh verlihirsh merged commit 73ca067 into feature/custom-chat-frontend Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants