fidget.nvim icon indicating copy to clipboard operation
fidget.nvim copied to clipboard

Close the floating window manually

Open rockyzhang24 opened this issue 2 years ago • 7 comments

When saving a session using a session management plugin, or even vim builtin mksession, if some floating windows are open, they will be recorded into the session file but as normal windows instead of floating windows. So in the future when we want to load the session, the window position and layout will be wrong.

131850590-e631d778-de33-4d3d-b839-0644d16f500e

My workaround is that before saving a session, close all the floating windows using the script below.

function M.close_all_floating_wins()
  for _, win in ipairs(vim.api.nvim_list_wins()) do
    local config = vim.api.nvim_win_get_config(win)
    if config.relative ~= "" then
      vim.api.nvim_win_close(win, false)
      -- print('Closing window', win)
    end
  end
end

However, the fidget floating windows cannot be closed. So I am wondering whether it is possible to add a command to close fidget manually? Or how can we check if fidget is running or not?

Thank you very much.

rockyzhang24 avatar Apr 28 '22 22:04 rockyzhang24

Have you tried :FidgetClose? https://github.com/j-hui/fidget.nvim/blob/main/doc/fidget.md#fidgetclose

j-hui avatar Apr 30 '22 03:04 j-hui

Yes I tried but I still cannot close its floating windows. I will try it again right now.

Hi @j-hui I tried it again already just now and the floating windows showing the progress couldn't be closed.

https://user-images.githubusercontent.com/11582667/166089986-70875504-e061-442e-bbb6-955b1da81fe2.mov

I ran : FidgetClose 3 times in a row however, the floating windows were still there.

Thank you.

rockyzhang24 avatar Apr 30 '22 03:04 rockyzhang24

I also encountered this problem, I was in the auto-session hook to do these operations The result is alleviated, but it still happens in very occasional cases

local opts = {
  log_level = 'info',
  auto_session_enable_last_session = false,
  auto_session_enabled = true,
  auto_save_enabled = nil,
  auto_restore_enabled = nil,
  auto_session_suppress_dirs = nil,

  pre_save_cmds = {
    "lua require'nvim-tree.view'.close()",
    "lua require'symbols-outline.preview'.close()",
    'FidgetClose()',  -- this line
  },
}

require('auto-session').setup(opts)

0x7a7a avatar May 01 '22 13:05 0x7a7a

Hi @j-hui any updates on this? Thank you.

rockyzhang24 avatar May 08 '22 20:05 rockyzhang24

@rockyzhang24 sorry I haven't had a chance to look into this yet

j-hui avatar May 11 '22 02:05 j-hui

@j-hui Okay no rush, I was just asking. Thank you.

rockyzhang24 avatar May 11 '22 04:05 rockyzhang24

The session save and restore issue if there are floating windows was fixed via this commit (https://github.com/neovim/neovim/commit/3fe6bf3a1e50299dbdd6314afbb18e468eb7ce08). So now, fidget won't bring about issues when we store the session with fidget progress floating windows open and restore later.

I believe an explicit command to close the floating windows manually is still useful. But no rush at all. :)

Thank you very much.

rockyzhang24 avatar May 22 '22 17:05 rockyzhang24

As of #143, you can now do this programmatically via fidget.notification.window.close() (technically an internal API, but let me know if it becomes an important part of your workflow, and I'll commit to stabilizing it).

Closing this issue for now, but let me know if there's any window management APIs you'd like exposed.

j-hui avatar Nov 10 '23 01:11 j-hui