Skip to content

Commit 4787c3d

Browse files
committed
fix: commands not behaving as expected
1 parent de2bef5 commit 4787c3d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/command/Menus.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -736,18 +736,25 @@ define(function (require, exports, module) {
736736
Metrics.countEvent(Metrics.EVENT_TYPE.UI_MENU, "click", menuItem._command.getID());
737737
logger.leaveTrail("UI Menu Click: " + menuItem._command.getID());
738738
MainViewManager.focusActivePane();
739-
if (menuItem._command._options.eventSource) {
740-
// NOTE: Ideally beforeExecuteCommand should be fired inside Command.execute itself.
741-
// But right now Command.execute() bypasses the event flow
742-
// So we run through CommandManager.execute() to keep things consistent
743-
// (keyboard + menu both go through the same path)
744-
// Read this for more info: https://github.com/phcode-dev/phoenix/pull/2356
745-
CommandManager.execute(menuItem._command.getID(), {
739+
const commandId = menuItem._command.getID();
740+
741+
// NOTE: we handle save commands differently because we want save commands to go through the
742+
// CommandManager.execute() to trigger beforeExecuteCommand events consistently, whether invoked via
743+
// menu click or keyboard shortcut.
744+
// because there are listeners that uses beforeExecuteCommand to listen to save commands
745+
// (for ex: tabbar listens to save commands to add placeholder tabs to working set)
746+
// Other commands use direct execution to preserve file tree context
747+
if(commandId === Commands.FILE_SAVE ||
748+
commandId === Commands.FILE_SAVE_AS ||
749+
commandId === Commands.FILE_SAVE_ALL) {
750+
CommandManager.execute(commandId);
751+
} else if (menuItem._command._options.eventSource) {
752+
menuItem._command.execute({
746753
eventSource: CommandManager.SOURCE_UI_MENU_CLICK,
747754
sourceType: self.id
748755
});
749756
} else {
750-
CommandManager.execute(menuItem._command.getID());
757+
menuItem._command.execute();
751758
}
752759
});
753760

0 commit comments

Comments
 (0)