sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.6k stars 101 forks source link

Close Diffview tabpage programatically #409

Closed gegoune closed 11 months ago

gegoune commented 11 months ago

Hey again, hope you are doing well!

Diffview and sessions are not good friends. If diffview's tabpage gets saved in session nvim is not restoring it properly upon session load; no file panel will show and INDEX window is always empty with WORKING TREE entirely showing as added (neither is actual state of repo). I am not sure whether it's a matter of adjusting sessionoptions or is it not expected to work at all.

Because of above issue I am planning to close diffview's tabpage before saving session (automating it). Unfortunately solution I found does not work properly either. I am trying:

  1. start nvim, open any file, open diffview: :DiffviewOpen
  2. go back to previous tab: gt
  3. attempt to close other tab with diffview windows: :tabdo DiffviewClose

Tab gets closed properly, but both windows showing diffs are now part of the only tabpage, no file panel shows, just diffs.

With above in mind, I hope you don't mind me asking if you know whether

Thank you!

sindrets commented 11 months ago

Your question lead me to discover a bug. That's now fixed. After the latest commit you can do the following to close all views programmatically:

for _, view in ipairs(require("diffview.lib").views) do
  view:close()
end

And to answer your question of "[is it] possible for sessions to correctly save and load diffview tabpage/windows?". Short answer is: not easily. I would have to implement some way to serialize views such that the internal state could be restored. This is not something I'm interested in looking into at the moment.

gegoune commented 11 months ago

That code works perfectly, thank you so much!

As to possibility of storing diffview into session it was more of question along lines of whether I have something misconfigured and it's suppose to work. I am happy with closing the view before saving session.