sindrets / diffview.nvim

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

on opening a new tab when none is present #349

Closed gennaro-tedesco closed 1 year ago

gennaro-tedesco commented 1 year ago

Thank you for the great work on this plugin!

Browsing through the issues I have seen often that you make a correct point in remarking that diffview always opens in its own tab (whenever people asked to juggle around with windows and buffers); however, I have noticed that it tends to open two tabs by default even when invoked as neovim starting argument. Let me explain: I have a shell function that lets me dynamically select branches to diff and upon selection I pass said branch to nvim "+DiffviewOpen $branches" (something along these lines). Doing so, diffview still opens two tabs, one tab for itself (with the git diff views) and another tab containing an empty buffer by default. The same behaviour also happens when opening diffview directly on start-up pages/dashboards like there are many in nvim these days.

https://user-images.githubusercontent.com/15387611/234508796-d93a5e37-c79a-4bf2-8b09-9f220f46b4d4.mov

Is this still intended behaviour, namely do you not think it would be possible to force diffview to only open another tab when a tab with a non-empty buffer is already present?

sindrets commented 1 year ago

Doing so, diffview still opens two tabs, one tab for itself (with the git diff views) and another tab containing an empty buffer by default.

Not quite. Nvim opens the first tab with the empty buffer. Naturally there must always be at least one tab. Thus, when you simply run nvim you end up in an empty buffer, in tab page 1. When you then invoke :DiffviewOpen the plugin opens its own tab page. Now there are two tab pages, but the plugin only created one.

[...] do you not think it would be possible to force diffview to only open another tab when a tab with a non-empty buffer is already present?

This would be unconventional. Commands that open tabs in vim, do not do so conditionally. I suggest that you instead do this in your shell function:

nvim +"DiffviewOpen $branches" +tabonly
gennaro-tedesco commented 1 year ago

You are perfectly right, +tabonly does the job seamlessly!