From f20b8f1a572b2c6a6e06b86cb6c2d6d391a24466 Mon Sep 17 00:00:00 2001 From: Joseph Atkins-Turkish Date: Fri, 2 Sep 2016 14:39:57 -0700 Subject: [PATCH] Cleanup and fixes --- ide/static/ide/css/ide.css | 7 +------ ide/static/ide/js/editor.js | 32 +++++++++++++------------------- ide/static/ide/js/fuzzyprompt.js | 2 +- ide/static/ide/js/resources.js | 22 ++++++++++++++++------ 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/ide/static/ide/css/ide.css b/ide/static/ide/css/ide.css index 22b40e89..ce5638fe 100644 --- a/ide/static/ide/css/ide.css +++ b/ide/static/ide/css/ide.css @@ -1137,16 +1137,12 @@ span.cm-autofilled-end { } .fuzzy-subheader { - /*background-color: #222;*/ font-weight: bold; - color: #555; + color: #666; font-variant: small-caps; margin-left: 1em; } -.fuzzy-subheader::before { - /*content: '-- ';*/ -} .fuzzy-hint { opacity: 0.5; @@ -1159,7 +1155,6 @@ span.cm-autofilled-end { } #fuzzy-results > div { - line-height: 28px; cursor: pointer; cursor: hand; diff --git a/ide/static/ide/js/editor.js b/ide/static/ide/js/editor.js index 9a46216b..9e83c7f2 100644 --- a/ide/static/ide/js/editor.js +++ b/ide/static/ide/js/editor.js @@ -240,7 +240,6 @@ CloudPebble.Editor = (function() { code_mirror.on('shown', function() { is_autocompleting = true; }); - current_editor = code_mirror; // The browser should probably do this without our help. Sometimes Safari doesn't. $(document).click(function(e) { @@ -482,13 +481,22 @@ CloudPebble.Editor = (function() { alert(gettext(interpolate("Failed to reload file. %s", [error]))); }); }; + + function set_save_shortcut() { + CloudPebble.GlobalShortcuts.SetShortcutHandlers({ + "PlatformCmd-S": save + }); + } + set_save_shortcut(); CloudPebble.Sidebar.SetActivePane(pane, { id: 'source-' + file.id, onRestore: function() { + current_editor = code_mirror; code_mirror.refresh(); _.defer(function() { code_mirror.focus(); }); check_safe(); + set_save_shortcut(); refresh_ib(); }, onSuspend: function() { @@ -496,6 +504,7 @@ CloudPebble.Editor = (function() { fullscreen(code_mirror, false); resume_fullscreen = true; } + current_editor = null; }, onDestroy: function() { if(!was_clean) { @@ -520,7 +529,7 @@ CloudPebble.Editor = (function() { CloudPebble.Sidebar.ClearIcon('source-' + file.id); }; - var save = function() { + function save() { // Make sure we're up to date with whatever changed in IB. if(ib_showing) { var content = code_mirror.getValue(); @@ -766,6 +775,7 @@ CloudPebble.Editor = (function() { var error_box = $('
'); error_box.text(interpolate(gettext("Something went wrong: %s"), [error.message])); CloudPebble.Sidebar.SetActivePane(error_box, {id: ''}); + throw error; }).finally(function() { CloudPebble.ProgressBar.Hide(); }); @@ -835,7 +845,7 @@ CloudPebble.Editor = (function() { var codemirror_commands = [ {command: 'indentAuto', refocus: true}, {command: 'toggleComment', hint: 'Cmd-/ or Ctrl-/', refocus: true}, - 'find', 'replace', 'indentMore', 'indentLess' + 'find', 'replace', 'indentMore', 'indentLess', 'save', 'saveAll' ]; _.each(codemirror_commands, function(entry) { @@ -848,26 +858,10 @@ CloudPebble.Editor = (function() { local_commands[name].hint = !!entry.hint ? entry.hint : CloudPebble.GlobalShortcuts.GetShortcutForCommand(command); }); - // local_commands[gettext('Auto Indent')] = function() { - // current_editor.execCommand('indentAuto'); - // current_editor.focus(); - // }; - // local_commands[gettext('Auto Indent')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('indentAuto'); - // local_commands[gettext('Find')] = function() { - // current_editor.execCommand('find'); - // }; - // local_commands[gettext('Find')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('find'); - - CloudPebble.FuzzyPrompt.AddCommands(gettext('File'), local_commands, function() { return (!!current_editor); }); - CloudPebble.GlobalShortcuts.SetShortcutHandlers({ - save: function() { - save().catch(alert); - } - }); CloudPebble.FuzzyPrompt.AddCommands(gettext('Actions'), global_commands); diff --git a/ide/static/ide/js/fuzzyprompt.js b/ide/static/ide/js/fuzzyprompt.js index c1388523..8b3cea06 100644 --- a/ide/static/ide/js/fuzzyprompt.js +++ b/ide/static/ide/js/fuzzyprompt.js @@ -33,7 +33,7 @@ CloudPebble.FuzzyPrompt = (function() { var options = { caseSensitive: false, sortFn: function(a, b) { - return (a.score === b.score) ? a.item.name.localeCompare(b) : a.score - b.score; + return (a.score === b.score) ? a.item.name.localeCompare(b.item.name) : a.score - b.score; }, shouldSort: true, threshold: 0.5, diff --git a/ide/static/ide/js/resources.js b/ide/static/ide/js/resources.js index 21263df1..d130dfc7 100644 --- a/ide/static/ide/js/resources.js +++ b/ide/static/ide/js/resources.js @@ -470,15 +470,28 @@ CloudPebble.Resources = (function() { if(list_entry) { list_entry.addClass('active'); } - + function set_save_shortcut() { + CloudPebble.GlobalShortcuts.SetShortcutHandlers({ + "PlatformCmd-S": save + }); + } + set_save_shortcut(); CloudPebble.Sidebar.SetActivePane(pane, { id: 'resource-' + resource.id, - onRestore: _.partial(restore_pane, pane) + onRestore: function() { + restore_pane(pane); + set_save_shortcut(); + }, + onSuspend: function() { + CloudPebble.GlobalShortcuts.SetShortcutHandlers({ + "PlatformCmd-S": function() {return false;} + }); + } }); pane.find('#edit-resource-type').val(resource.kind).attr('disabled', 'disabled'); pane.find('#edit-resource-type').change(); - var save = function(e) { + function save(e) { if (e) e.preventDefault(); process_resource_form(form, false, resource.file_name, "/ide/project/" + PROJECT_ID + "/resource/" + resource.id + "/update").then(function(data) { delete project_resources[resource.file_name]; @@ -764,9 +777,6 @@ CloudPebble.Resources = (function() { }).init(); form.submit(save); - CloudPebble.GlobalShortcuts.SetShortcutHandlers({ - save: save - }); restore_pane(pane); }).finally(function() {