Skip to content

Commit 3080fb5

Browse files
devvaannshabose
authored andcommitted
feat: add placeholder tab to working set when save is clicked
1 parent 8730bc4 commit 3080fb5

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/command/Menus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,12 @@ define(function (require, exports, module) {
737737
logger.leaveTrail("UI Menu Click: " + menuItem._command.getID());
738738
MainViewManager.focusActivePane();
739739
if (menuItem._command._options.eventSource) {
740-
menuItem._command.execute({
740+
CommandManager.execute(menuItem._command.getID(), {
741741
eventSource: CommandManager.SOURCE_UI_MENU_CLICK,
742742
sourceType: self.id
743743
});
744744
} else {
745-
menuItem._command.execute();
745+
CommandManager.execute(menuItem._command.getID());
746746
}
747747
});
748748

src/extensionsIntegrated/TabBar/main.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)