folke / snacks.nvim

🍿 A collection of small QoL plugins for Neovim
Apache License 2.0
982 stars 16 forks source link

bug: Dashboard crashes when the width of the terminal is smaller than the specified width for the dashboard #104

Closed LinkUpGames closed 3 hours ago

LinkUpGames commented 3 hours ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.2

Operating system/version

Linux 6.11.7

Describe the bug

If I set the default width for the dashboard to a value greater than the size that the screen can be rendered in (width = 100), the plugin crashes:

Error detected while processing UIEnter Autocommands for "*":
Error executing lua callback: ...cal/share/nvim/lazy/snacks.nvim/lua/snacks/dashboard.
lua:549: table index is NaN
stack traceback:
        ...cal/share/nvim/lazy/snacks.nvim/lua/snacks/dashboard.lua:549: in function '
layout'
        ...cal/share/nvim/lazy/snacks.nvim/lua/snacks/dashboard.lua:660: in function '
update'
        ...cal/share/nvim/lazy/snacks.nvim/lua/snacks/dashboard.lua:211: in function '
open'
        ...cal/share/nvim/lazy/snacks.nvim/lua/snacks/dashboard.lua:1047: in function
'setup'
        ...s/.local/share/nvim/lazy/snacks.nvim/lua/snacks/init.lua:126: in function <
...s/.local/share/nvim/lazy/snacks.nvim/lua/snacks/init.lua:123>

Steps To Reproduce

  1. Update the default width to 100 and quit Neovim
  2. Resize the window terminal. I set the width of my terminal to half that of my computer monitor (1920x1080)
  3. Start Neovim

Expected Behavior

I think dashboard.nvim resolved this by just cutting out the edges on the header when it was overflowing.

Repro

return {
  "folke/snacks.nvim",
  lazy = false,
  opts = function()
    local logo = [[
 _____                                                                                 _____ 
( ___ )                                                                               ( ___ )
 |   |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|   | 
 |   | ███████╗ ██████╗ ██████╗██╗     ███████╗███████╗        █████╗     ██╗ ██████╗  |   | 
 |   | ██╔════╝██╔════╝██╔════╝██║     ██╔════╝██╔════╝       ██╔══██╗██╗███║██╔═████╗ |   | 
 |   | █████╗  ██║     ██║     ██║     █████╗  ███████╗       ╚██████║╚═╝╚██║██║██╔██║ |   | 
 |   | ██╔══╝  ██║     ██║     ██║     ██╔══╝  ╚════██║        ╚═══██║██╗ ██║████╔╝██║ |   | 
 |   | ███████╗╚██████╗╚██████╗███████╗███████╗███████║██╗     █████╔╝╚═╝ ██║╚██████╔╝ |   | 
 |   | ╚══════╝ ╚═════╝ ╚═════╝╚══════╝╚══════╝╚══════╝╚═╝     ╚════╝     ╚═╝ ╚═════╝  |   | 
 |___|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|___| 
(_____)                                                                               (_____)
   ]]

    local keys = {
      { icon = " ", key = "f", desc = "Find File", action = ":lua Snacks.dashboard.pick('files')" },
      { icon = " ", key = "s", desc = "Restore Session", section = "session" },
      {
        icon = " ",
        key = "c",
        desc = "Config",
        action = ":lua Snacks.dashboard.pick('files', {cwd = vim.fn.stdpath('config')})",
      },
      { icon = "󰒲 ", key = "L", desc = "Lazy", action = ":Lazy", enabled = package.loaded.lazy },
      { icon = " ", key = "q", desc = "Quit", action = ":qa" },
    }

    return {
      dashboard = {
        width = 100, -- This is the value I changed, if I set it to 60 then it does not crash
        enabled = true,
        pane_gap = 1,
        preset = {
          header = logo,
          keys = keys,
        },
        sections = {
          { section = "header" },
          { section = "keys", padding = 1, gap = 1 },
          { section = "startup" },
        },
      },
    }
  end,
}
folke commented 3 hours ago

Should be fixed now. Thank you for reporting.

LinkUpGames commented 2 hours ago

Thank you!