sindrets / diffview.nvim

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

fix: cancel update if view becomes out of focus #472

Closed 8veStory closed 1 month ago

8veStory commented 3 months ago

Fixes #462.

I work in a large monorepo and noticed that when :DiffviewOpen was used, and you switched to another tab, you would switch back to the Diffview window.

Reason for this being that inside the async function DiffView:update_file(), it is possible for the line local err, new_files = await(self:get_updated_files()) to take a long amount of time in large git repos. This meant it's possible for a user to switch to another tab prior to the async function completing, in which at the end of the function the user's window is switched to the DiffView.

I'm not entirely familiar with Lua but I made a very rough PR that changes the order of when re-rendering the panels work to abate this issue.

sindrets commented 1 month ago

@8veStory sorry for hijacking your PR. I think this should solve the issue you described, but let me know if you still have any problems, and we can iterate on this.