Skip to content

NvDash: Mouse Invoked Invalid Cursor Position Causes Error  #544

Description

@ochi12

How to reproduce this issue:

  1. open nvdash
  2. click anywhere from the nvdash buffer except for the item areas
  3. navigate up and down
  4. an error message should appear.

Error produced:

E5108: Lua: ...i12/.local/share/nvim/lazy/ui/lua/nvchad/nvdash/init.lua:214: Expected 2 arguments
stack traceback:                                                                                              
        [C]: in function 'nvim_win_set_cursor'                                                                
        ...i12/.local/share/nvim/lazy/ui/lua/nvchad/nvdash/init.lua:214: in function <...i12/.local/share/nvim
/lazy/ui/lua/nvchad/nvdash/init.lua:213> 

Why the above error appears:

 local key_movements = function(n, cmd)
    local curline = fn.line "."

    for i, v in ipairs(key_lines) do
      if v.i == curline then
        local x = key_lines[i + n] or key_lines[n == 1 and 1 or #key_lines]
        if cmd and x.cmd then
          vim.cmd(x.cmd)
        else
          return { x.i, x.col }
        end
      end
    end
  end

as you can see this function responsible for returning the new cursor position doesn't always return a valid line and col coordinates. Instead a return value only occurs inside the if v.i == curline scope . when v.i is not equal to curline ( in invalid cursor pos), it returns a nil and we see the error I pasted above.

Suggested fix / handling:

diff --git a/lua/nvchad/nvdash/init.lua b/lua/nvchad/nvdash/init.lua
index f36f3fb..c4cacfa 100644
--- a/lua/nvchad/nvdash/init.lua
+++ b/lua/nvchad/nvdash/init.lua
@@ -193,17 +193,29 @@ M.open = function(buf, win, action)
 
   local key_movements = function(n, cmd)
     local curline = fn.line "."
+    local target_i = nil;
 
     for i, v in ipairs(key_lines) do
       if v.i == curline then
-        local x = key_lines[i + n] or key_lines[n == 1 and 1 or #key_lines]
-        if cmd and x.cmd then
-          vim.cmd(x.cmd)
-        else
-          return { x.i, x.col }
+        target_i = i + n
+      elseif curline > key_lines[1].i and curline < key_lines[#key_lines].i then
+        if key_lines[i].i < curline and key_lines[i + 1].i > curline then
+          if n > 0 then 
+            target_i = i + n
+          else
+            target_i = i
+          end
+          break
         end
       end
     end
+
+    local x = key_lines[target_i] or key_lines[(n == 1) and 1 or #key_lines]
+    if cmd and x.cmd then
+      vim.cmd(x.cmd)
+    else
+      return { x.i, x.col }
+    end
   end

This fix detection for nearest button.

Preview:

Screencast.From.2026-04-11.02-06-52.mp4

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