@@ -327,6 +327,12 @@ DiffView.update_files = debounce.debounce_trailing(
327
327
async .wrap (function (self , callback )
328
328
await (async .scheduler ())
329
329
330
+ -- Never update unless the view is in focus
331
+ if self .tabpage ~= api .nvim_get_current_tabpage () then
332
+ callback ({ " The update was cancelled." })
333
+ return
334
+ end
335
+
330
336
--- @type PerfTimer
331
337
local perf = PerfTimer (" [DiffView] Status Update" )
332
338
self :ensure_layout ()
@@ -344,19 +350,24 @@ DiffView.update_files = debounce.debounce_trailing(
344
350
end
345
351
346
352
local index_stat = pl :stat (pl :join (self .adapter .ctx .dir , " index" ))
347
- local last_winid = api .nvim_get_current_win ()
348
353
349
354
--- @type string[] ?, FileDict
350
355
local err , new_files = await (self :get_updated_files ())
356
+ await (async .scheduler ())
351
357
352
358
if err then
353
359
utils .err (" Failed to update files in a diff view!" , true )
354
360
logger :error (" [DiffView] Failed to update files!" )
355
- await (async .scheduler ())
356
361
callback (err )
357
362
return
358
363
end
359
364
365
+ -- Stop the update if the view is no longer in focus.
366
+ if self .tabpage ~= api .nvim_get_current_tabpage () then
367
+ callback ({ " The update was cancelled." })
368
+ return
369
+ end
370
+
360
371
perf :lap (" received new file list" )
361
372
362
373
local files = {
@@ -365,8 +376,6 @@ DiffView.update_files = debounce.debounce_trailing(
365
376
{ cur_files = self .files .staged , new_files = new_files .staged },
366
377
}
367
378
368
- await (async .scheduler ())
369
-
370
379
for _ , v in ipairs (files ) do
371
380
-- We diff the old file list against the new file list in order to find
372
381
-- the most efficient way to morph the current list into the new. This
@@ -473,10 +482,6 @@ DiffView.update_files = debounce.debounce_trailing(
473
482
end
474
483
self :set_file (self .panel .cur_file or self .panel :next_file (), false , not self .initialized )
475
484
476
- if api .nvim_win_is_valid (last_winid ) then
477
- api .nvim_set_current_win (last_winid )
478
- end
479
-
480
485
self .update_needed = false
481
486
perf :time ()
482
487
logger :lvl (5 ):debug (perf )
0 commit comments