@@ -547,6 +547,44 @@ define(function (require, exports, module) {
547547 // the event fires too frequently when switching editors, leading to unexpected behavior
548548 const debounceUpdateTabs = _ . debounce ( updateTabs , 2 ) ;
549549
550+ /**
551+ * This function is responsible to add the placeholder tab to the working set (if user press save on it)
552+ * @param {Event } event
553+ * @param {String } commandId - the command id, to make sure we check it do the operation only on file save
554+ */
555+ function onFileSave ( event , commandId ) {
556+ if ( commandId === Commands . FILE_SAVE || commandId === Commands . FILE_SAVE_ALL ) {
557+ const activePane = MainViewManager . getActivePaneId ( ) ;
558+ const currentFile = MainViewManager . getCurrentlyViewedFile ( activePane ) ;
559+
560+ if ( currentFile ) {
561+ const filePath = currentFile . fullPath ;
562+
563+ // check if this file is currently shown as a placeholder in any pane
564+ const isFirstPanePlaceholder =
565+ MainViewManager . getCurrentlyViewedFile ( "first-pane" ) &&
566+ MainViewManager . getCurrentlyViewedFile ( "first-pane" ) . fullPath === filePath &&
567+ ! Global . firstPaneWorkingSet . some ( ( entry ) => entry . path === filePath ) ;
568+
569+ const isSecondPanePlaceholder =
570+ MainViewManager . getCurrentlyViewedFile ( "second-pane" ) &&
571+ MainViewManager . getCurrentlyViewedFile ( "second-pane" ) . fullPath === filePath &&
572+ ! Global . secondPaneWorkingSet . some ( ( entry ) => entry . path === filePath ) ;
573+
574+ // if it's a placeholder tab, we add it to the working set
575+ if ( isFirstPanePlaceholder ) {
576+ const fileObj = FileSystem . getFileForPath ( filePath ) ;
577+ MainViewManager . addToWorkingSet ( "first-pane" , fileObj ) ;
578+ }
579+
580+ if ( isSecondPanePlaceholder ) {
581+ const fileObj = FileSystem . getFileForPath ( filePath ) ;
582+ MainViewManager . addToWorkingSet ( "second-pane" , fileObj ) ;
583+ }
584+ }
585+ }
586+ }
587+
550588 /**
551589 * Registers the event handlers
552590 */
@@ -588,6 +626,10 @@ define(function (require, exports, module) {
588626 // main-plugin-panel[0] = live preview panel
589627 new ResizeObserver ( updateTabs ) . observe ( $ ( "#main-plugin-panel" ) [ 0 ] ) ;
590628
629+ // listen for file save commands, needed to add placeholder tab to the working set
630+ CommandManager . off ( "beforeExecuteCommand" , onFileSave ) ;
631+ CommandManager . on ( "beforeExecuteCommand" , onFileSave ) ;
632+
591633 // File dirty flag change handling
592634 DocumentManager . on ( "dirtyFlagChange" , function ( event , doc ) {
593635 const filePath = doc . file . fullPath ;
0 commit comments