OXY2DEV / intro.nvim

MIT License
25 stars 2 forks source link

use with nvimtree #5

Closed zerochae closed 5 months ago

zerochae commented 5 months ago

Thank you for creating such an amazing nvim plugin.

I have discovered an issue when using it together with the nvim-tree plugin.

The issue is that when nvimTree is opened on the left or right side, the renderer does not function properly.

I have resolved the issue by writing an autocmd.

Since many users are likely to use nvim-tree, could you add this as a default feature?

I think it might be necessary to add a feature in intro.nvim that re-renders every time a split window is opened.

If you prefer, I can create a PR.

autocmd("BufUnload", {
  pattern = "NvimTree_*",
  callback = function()
    local win_id_list = vim.api.nvim_list_wins()
    for _, win_id in ipairs(win_id_list) do
      local filetype = vim.bo[vim.api.nvim_win_get_buf(win_id)].filetype
      if filetype == "intro" then
        vim.schedule(function()
          vim.api.nvim_set_current_win(win_id)
          vim.cmd "Refresh"
        end)
      end
    end
  end,
})

autocmd("FileType", {
  pattern = "NvimTree",
  callback = function()
    local win_id_list = vim.api.nvim_list_wins()
    local intro_win_id = nil
    local nvim_tree_win_id = nil

    for _, win_id in ipairs(win_id_list) do
      local filetype = vim.bo[vim.api.nvim_win_get_buf(win_id)].filetype
      if filetype == "intro" then
        intro_win_id = win_id
      elseif filetype == "NvimTree" then
        nvim_tree_win_id = win_id
      end
    end

    if nvim_tree_win_id ~= nil and intro_win_id ~= nil then
      vim.schedule(function()
        vim.api.nvim_set_current_win(intro_win_id)
        vim.cmd [[
          Refresh
          NvimTreeFocus
        ]]
      end)
    end
  end,
})
as-is to -be
as-is to-be
OXY2DEV commented 5 months ago

That's intentional. Because it was meant to be used with stuff like telescope & noice(basically things that use semi-transparent floating windows). I actually planned it to act like a background image when you have other stuff on the screen.

I am planning on rewriting the entire plugin(cause it's not particularly good at what it does and I basically did the thing no prior knowledge). So, I will add that as an option there.

Also, there is a BUG that may cause neovim to crash if some other window(e.g. Lazy.nvim) opens instead of the normal window in neovim during startup. So, if you plan on using the plugin you should know about this(though it is a rare thing).

Thanks for trying the plugin(even though it may be a bit unstable in certain cases).