@@ -240,7 +240,6 @@ CloudPebble.Editor = (function() {
240240 code_mirror . on ( 'shown' , function ( ) {
241241 is_autocompleting = true ;
242242 } ) ;
243- current_editor = code_mirror ;
244243
245244 // The browser should probably do this without our help. Sometimes Safari doesn't.
246245 $ ( document ) . click ( function ( e ) {
@@ -482,20 +481,30 @@ CloudPebble.Editor = (function() {
482481 alert ( gettext ( interpolate ( "Failed to reload file. %s" , [ error ] ) ) ) ;
483482 } ) ;
484483 } ;
484+
485+ function set_save_shortcut ( ) {
486+ CloudPebble . GlobalShortcuts . SetShortcutHandlers ( {
487+ "PlatformCmd-S" : save
488+ } ) ;
489+ }
490+ set_save_shortcut ( ) ;
485491
486492 CloudPebble . Sidebar . SetActivePane ( pane , {
487493 id : 'source-' + file . id ,
488494 onRestore : function ( ) {
495+ current_editor = code_mirror ;
489496 code_mirror . refresh ( ) ;
490497 _ . defer ( function ( ) { code_mirror . focus ( ) ; } ) ;
491498 check_safe ( ) ;
499+ set_save_shortcut ( ) ;
492500 refresh_ib ( ) ;
493501 } ,
494502 onSuspend : function ( ) {
495503 if ( is_fullscreen ) {
496504 fullscreen ( code_mirror , false ) ;
497505 resume_fullscreen = true ;
498506 }
507+ current_editor = null ;
499508 } ,
500509 onDestroy : function ( ) {
501510 if ( ! was_clean ) {
@@ -520,7 +529,7 @@ CloudPebble.Editor = (function() {
520529 CloudPebble . Sidebar . ClearIcon ( 'source-' + file . id ) ;
521530 } ;
522531
523- var save = function ( ) {
532+ function save ( ) {
524533 // Make sure we're up to date with whatever changed in IB.
525534 if ( ib_showing ) {
526535 var content = code_mirror . getValue ( ) ;
@@ -766,6 +775,7 @@ CloudPebble.Editor = (function() {
766775 var error_box = $ ( '<div class="alert alert-error"></div>' ) ;
767776 error_box . text ( interpolate ( gettext ( "Something went wrong: %s" ) , [ error . message ] ) ) ;
768777 CloudPebble . Sidebar . SetActivePane ( error_box , { id : '' } ) ;
778+ throw error ;
769779 } ) . finally ( function ( ) {
770780 CloudPebble . ProgressBar . Hide ( ) ;
771781 } ) ;
@@ -835,7 +845,7 @@ CloudPebble.Editor = (function() {
835845 var codemirror_commands = [
836846 { command : 'indentAuto' , refocus : true } ,
837847 { command : 'toggleComment' , hint : 'Cmd-/ or Ctrl-/' , refocus : true } ,
838- 'find' , 'replace' , 'indentMore' , 'indentLess'
848+ 'find' , 'replace' , 'indentMore' , 'indentLess' , 'save' , 'saveAll'
839849 ] ;
840850
841851 _ . each ( codemirror_commands , function ( entry ) {
@@ -848,26 +858,10 @@ CloudPebble.Editor = (function() {
848858 local_commands [ name ] . hint = ! ! entry . hint ? entry . hint : CloudPebble . GlobalShortcuts . GetShortcutForCommand ( command ) ;
849859 } ) ;
850860
851- // local_commands[gettext('Auto Indent')] = function() {
852- // current_editor.execCommand('indentAuto');
853- // current_editor.focus();
854- // };
855- // local_commands[gettext('Auto Indent')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('indentAuto');
856- // local_commands[gettext('Find')] = function() {
857- // current_editor.execCommand('find');
858- // };
859- // local_commands[gettext('Find')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('find');
860-
861-
862861 CloudPebble . FuzzyPrompt . AddCommands ( gettext ( 'File' ) , local_commands , function ( ) {
863862 return ( ! ! current_editor ) ;
864863 } ) ;
865864
866- CloudPebble . GlobalShortcuts . SetShortcutHandlers ( {
867- save : function ( ) {
868- save ( ) . catch ( alert ) ;
869- }
870- } ) ;
871865
872866 CloudPebble . FuzzyPrompt . AddCommands ( gettext ( 'Actions' ) , global_commands ) ;
873867
0 commit comments