Skip to content

[Bug] Attempt to index nil when pressing <CR> on first line of keymap popup #469

@Diomendius

Description

@Diomendius

Description

When <CR> is pressed with the cursor on the first line of the g? keymap overview, a Lua error is triggered by an attempt to index the nil variable context at help_panel.lua:85:

function HelpPanel:apply_cmd()
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
local comp = self.components.comp:get_comp_on_line(row)
if comp then
local mapping = comp.context.mapping
local last_winid = vim.fn.win_getid(vim.fn.winnr("#"))
if mapping then
api.nvim_win_call(last_winid, function()
api.nvim_feedkeys(utils.t(mapping[2]), "m", false)
end)
self:close()
end
end
end

Pressing <CR> on any other line does not trigger the error.

Expected behavior

The keypress should be ignored without error.

Actual behavior

This error appears:

E5108: Error executing lua: ...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:85: attempt to index field 'context' (a nil value)
stack traceback:
        ...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:85: in function 'apply_cmd'
        ...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:109: in function <...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:108>

Steps to reproduce

  1. nvim --clean -u mini.lua
  2. Create a dummy Git repo with :!git init, or :cd to an existing one.
  3. :DiffviewOpen
  4. g?
  5. Leaving the cursor at the top of the popup window, press <CR>

Health check

Output of :checkhealth diffview
Checking plugin dependencies ~
- OK nvim-web-devicons installed.

Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- OK Git found.
- OK Git is up-to-date. (2.44.0)
- WARNING Configured `hg_cmd` is not executable: 'hg'

Log info

No response

Neovim version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1702233742

Operating system and version

Linux 6.7.8-arch1-1 x86_64 GNU/Linux

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
vim.fn.mkdir(root, "p")

-- set stdpaths to use root
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "sindrets/diffview.nvim",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    config = function()
      require("diffview").setup({
        -- ##############################################################################
        -- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
        -- ##############################################################################
      })
    end,
  },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}
require("lazy").setup(plugins, { root = root .. "/plugins" })
require("lazy").sync({ show = false, wait = true })

vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions