luukvbaal / nnn.nvim

File manager for Neovim powered by nnn.
BSD 3-Clause "New" or "Revised" License
422 stars 9 forks source link

nnn fullscreen always errors when closing #101

Open FabioAntunes opened 2 months ago

FabioAntunes commented 2 months ago

This change https://github.com/luukvbaal/nnn.nvim/commit/62b01532a9dcb0111459b308668aebdb0088bfd8#

Introduced some bug when starting nvim . and nnn is in explorer mode.

I have modified the nnn.lua to print the existing variables hopefully this will help understanding the issue:

The original code:

-- Close and re-open explorer when it was fullscreen
  if mode == "explorer" and state[mode][tab].fs then
    a.nvim_win_close(state[mode][tab].win, {force = true})
    M.toggle("explorer", false, false)
    c("vert resize +1 | vert resize -1 | wincmd p")
  end

What I added:

  if mode == "explorer" and state[mode][tab].fs then
+    vim.print(state[mode][tab].win)
+    vim.print(state[mode][tab])
+    vim.print(state[mode])
+    vim.print(a.nvim_list_wins())
+    vim.print(a.nvim_tabpage_list_wins(0))
    a.nvim_win_close(state[mode][tab].win, {force = true})
    M.toggle("explorer", false, false)
    c("vert resize +1 | vert resize -1 | wincmd p")
  end

And this is the output of the :messages

nil
{
  buf = 1,
  fs = true,
  id = 3
}
{ {
    buf = 1,
    fs = true,
    id = 3
  } }
{ 1000 }
{ 1000 }
Error executing vim.schedule lua callback: ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:132: Invalid 'window': Expected Lua nu
mber
stack traceback:
        [C]: in function 'nvim_win_close'
        ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:132: in function 'handle_files'
        ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:164: in function <...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn
.lua:163>

As you can see there's no win property in the state[mode][tab]

As for the configs for nnn I'm using packer and requiring a file with the configs:

-- packer/lua
use({
    "luukvbaal/nnn.nvim",
    config = function()
      require("fantunes.plugins.nnn-nvim")
    end,
  })

-- ------------------------------------------
-- fantunes.plugins.nnn-nvim.lua
vim.cmd([[packadd nvim-web-devicons]])
local map = vim.api.nvim_set_keymap
local mapOpts = { noremap = true }

map("n", "<leader>nn", ":NnnExplorer<CR>", mapOpts)

require("nnn").setup({
  explorer = {
    cmd = "nnn -H",
  },
  replace_netrw = "explorer",
  auto_close = true,
  windownav = {
    left = "<C-h>",
    right = "<C-l>",
  },
})

There are a few more issues with these changes, but I can raise them in separate issues if you prefer?

For now I have reverted to a previous commit:

use({
    "luukvbaal/nnn.nvim",
    commit = "62b01532a9dcb0111459b308668aebdb0088bfd8",
    config = function()
      require("fantunes.plugins.nnn-nvim")
    end,
  })

Let me know if you need any more info.