Cant quit neovim when window is the last and snacks explorer is still open

Snacks is a great plugin for neovim that allows you to quickly open and close windows. However, it has a bug to quit neovim when only one window is left and snacks explorer still open. This is very annoying, but I found a workaround solution for it.

Regarding the discussion, the snacks plugin did not handle the QuitPre event properly. So they created a custom autocmd to handle this event, which will close the explorer along with quitting neovim.

Here the snippet of code to handle the QuitPre event and close the snacks windows:

vim.api.nvim_create_autocmd('QuitPre', {
    callback = function()
        local snacks_windows = {}
        local floating_windows = {}
        local windows = vim.api.nvim_list_wins()
        for _, w in ipairs(windows) do
            local filetype = vim.api.nvim_get_option_value('filetype', { buf = vim.api.nvim_win_get_buf(w) })
            if filetype:match('snacks_') ~= nil then
                table.insert(snacks_windows, w)
            elseif vim.api.nvim_win_get_config(w).relative ~= '' then
                table.insert(floating_windows, w)
            end
        end
        if 1 == #windows - #floating_windows - #snacks_windows then
            -- Should quit, so we close all Snacks windows.
            for _, w in ipairs(snacks_windows) do
                vim.api.nvim_win_close(w, true)
            end
        end
    end,
})