Skip to content

Stale 'q' keymap persists after closing CopilotChat, causing E5108 on second press #1535

@eugoss

Description

@eugoss

After opening CopilotChat, then typing gh (help) or gc (info) and closing it with q, the q keymap is not cleaned up. Pressing q a second time triggers an E5108 Lua error due to an attempt to restore a buffer to an already-invalid window.

To Reproduce

  1. Open CopilotChat (e.g. :CopilotChat)
  2. Press gh to show help, or gc to show info
  3. Press q to close CopilotChat
  4. Press q again

Expected behavior

The q keymap should be removed once the CopilotChat window is closed. Pressing q afterwards should have no effect or fall through to the default Neovim behavior.

Actual behavior

An error is thrown:

E5108: Error executing lua: ...vim/lazy/CopilotChat.nvim/lua/CopilotChat/ui/overlay.lua:119: Invalid 'window': Expected Lua number
stack traceback:
    [C]: in function 'nvim_win_set_buf'
    ...vim/lazy/CopilotChat.nvim/lua/CopilotChat/ui/overlay.lua:119: in function 'restore'
    ...e/nvim/lazy/CopilotChat.nvim/lua/CopilotChat/ui/chat.lua:163: in function <...e/nvim/lazy/CopilotChat.nvim/lua/CopilotChat/ui/chat.lua:162>

Running :map q after closing the window confirms the stale mapping is still active:

n  q     * <Lua 298: ~/.local/share/nvim/lazy/CopilotChat.nvim/lua/CopilotChat/ui/chat.lua:162>

Environment

  • NVIM v0.11.6, Build type: RelWithDebInfo, LuaJIT 2.1.1772619647
  • OS: macOS and Linux (reproduced on both)
  • Plugin: CopilotChat.nvim (via lazy.nvim)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions