@@ -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