@@ -473,7 +473,16 @@ def on_pre_save(self, view):
473473 if ts_settings .get ("trailing_spaces_trim_on_save" ):
474474 view .run_command ("delete_trailing_spaces" )
475475
476+ def on_close (self , view ):
477+ # untrack
478+ active_views .pop (view .id (), None )
479+
476480 def update_on_region_change (self , view ):
481+ # remove views not currently visible
482+ if not self .is_view_visible (view ):
483+ active_views .pop (view .id (), None )
484+ return
485+
477486 # compare the currently visible region to the previous (if any) and
478487 # update if there were changes
479488 if view .visible_region () != active_views .get (view .id (), view .visible_region ()):
@@ -500,6 +509,34 @@ def freeze_last_version(self, view):
500509 with codecs .open (file_name , "r" , "utf-8" ) as f :
501510 on_disk = f .read ().splitlines ()
502511
512+ def is_view_visible (self , view ):
513+ window = view .window ()
514+ if not window :
515+ return False
516+
517+ # panel views don't trigger on_close but are also not valid anymore
518+ # after being hidden, so try to detect these cases here
519+ if view .size () == 0 and not view .file_name ():
520+ return False
521+
522+ # see if this view is visible in its group
523+ group = window .get_view_index (view )[0 ]
524+ if group != - 1 :
525+ return view .id () == window .active_view_in_group (group ).id ()
526+
527+ # check if this view is the active panel
528+ active_panel = window .active_panel () or ""
529+
530+ # find_output_panel only works without the "output."" prefix
531+ if active_panel .startswith ("output." ):
532+ active_panel = active_panel [len ("output." ):]
533+
534+ panel_view = window .find_output_panel (active_panel )
535+ if panel_view and view .id () == panel_view .id ():
536+ return True
537+
538+ return False
539+
503540
504541# Public: Deletes the trailing spaces.
505542class DeleteTrailingSpacesCommand (sublime_plugin .TextCommand ):
0 commit comments