diff --git a/src/command/Menus.js b/src/command/Menus.js index b1c137b621..30e358df89 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -737,12 +737,12 @@ define(function (require, exports, module) { logger.leaveTrail("UI Menu Click: " + menuItem._command.getID()); MainViewManager.focusActivePane(); if (menuItem._command._options.eventSource) { - menuItem._command.execute({ + CommandManager.execute(menuItem._command.getID(), { eventSource: CommandManager.SOURCE_UI_MENU_CLICK, sourceType: self.id }); } else { - menuItem._command.execute(); + CommandManager.execute(menuItem._command.getID()); } }); diff --git a/src/extensionsIntegrated/TabBar/main.js b/src/extensionsIntegrated/TabBar/main.js index 9c43888f3f..5f8f1b76f0 100644 --- a/src/extensionsIntegrated/TabBar/main.js +++ b/src/extensionsIntegrated/TabBar/main.js @@ -547,6 +547,44 @@ define(function (require, exports, module) { // the event fires too frequently when switching editors, leading to unexpected behavior const debounceUpdateTabs = _.debounce(updateTabs, 2); + /** + * This function is responsible to add the placeholder tab to the working set (if user press save on it) + * @param {Event} event + * @param {String} commandId - the command id, to make sure we check it do the operation only on file save + */ + function onFileSave(event, commandId) { + if (commandId === Commands.FILE_SAVE || commandId === Commands.FILE_SAVE_ALL) { + const activePane = MainViewManager.getActivePaneId(); + const currentFile = MainViewManager.getCurrentlyViewedFile(activePane); + + if (currentFile) { + const filePath = currentFile.fullPath; + + // check if this file is currently shown as a placeholder in any pane + const isFirstPanePlaceholder = + MainViewManager.getCurrentlyViewedFile("first-pane") && + MainViewManager.getCurrentlyViewedFile("first-pane").fullPath === filePath && + !Global.firstPaneWorkingSet.some((entry) => entry.path === filePath); + + const isSecondPanePlaceholder = + MainViewManager.getCurrentlyViewedFile("second-pane") && + MainViewManager.getCurrentlyViewedFile("second-pane").fullPath === filePath && + !Global.secondPaneWorkingSet.some((entry) => entry.path === filePath); + + // if it's a placeholder tab, we add it to the working set + if (isFirstPanePlaceholder) { + const fileObj = FileSystem.getFileForPath(filePath); + MainViewManager.addToWorkingSet("first-pane", fileObj); + } + + if (isSecondPanePlaceholder) { + const fileObj = FileSystem.getFileForPath(filePath); + MainViewManager.addToWorkingSet("second-pane", fileObj); + } + } + } + } + /** * Registers the event handlers */ @@ -588,6 +626,10 @@ define(function (require, exports, module) { // main-plugin-panel[0] = live preview panel new ResizeObserver(updateTabs).observe($("#main-plugin-panel")[0]); + // listen for file save commands, needed to add placeholder tab to the working set + CommandManager.off("beforeExecuteCommand", onFileSave); + CommandManager.on("beforeExecuteCommand", onFileSave); + // File dirty flag change handling DocumentManager.on("dirtyFlagChange", function (event, doc) { const filePath = doc.file.fullPath;