瀏覽代碼

[spark] Enable ctrl-enter for execution from ace editors

Johan Ahlen 10 年之前
父節點
當前提交
0963c90

+ 3 - 0
apps/spark/src/spark/static/spark/js/spark.ko.js

@@ -359,6 +359,9 @@ var Snippet = function (vm, notebook, snippet) {
   };
 
   self.execute = function () {
+    if (self.status() == 'running' || self.status() == 'loading') {
+      return;
+    }
     $(document).trigger("executeStarted", self);
     $(".jHueNotify").hide();
     logGA('/execute/' + self.type());

+ 9 - 1
apps/spark/src/spark/templates/editor_components.mako

@@ -438,7 +438,15 @@ from django.utils.translation import ugettext as _
           <input type="text" data-bind="value: value" />
         </div>
       </div>
-      <div class="ace-editor" data-bind="attr: {id: id()}, aceEditor: {value: statement_raw, aceInstance: ace, mode: aceEditorMode, extraCompleters: completers, errors: errors, autocompleter: aceAutocomplete, placeholder: $root.snippetPlaceholders[type()] }"></div>
+      <div class="ace-editor" data-bind="attr: { id: id() }, aceEditor: {
+          value: statement_raw,
+          onExecute: execute,
+          aceInstance: ace,
+          mode: aceEditorMode,
+          extraCompleters: completers,
+          errors: errors,
+          autocompleter: aceAutocomplete,
+          placeholder: $root.snippetPlaceholders[type()] }"></div>
       </div>
   </div>
 

+ 10 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -1492,6 +1492,7 @@ ko.bindingHandlers.aceEditor = {
     var onCopy = options.onCopy || function () {};
     var onPaste = options.onPaste || function () {};
     var onAfterExec = options.onAfterExec || function () {};
+    var onExecute = options.onExecute || function () {};
     var autocompleter = options.autocompleter || null;
 
     $el.text(options.value());
@@ -1662,6 +1663,15 @@ ko.bindingHandlers.aceEditor = {
       onChange(e, editor, valueAccessor);
     });
 
+    editor.commands.addCommand({
+      name: "execute",
+      bindKey: {win: "Ctrl-Enter", mac: "Command-Enter|Ctrl-Enter"},
+      exec: function() {
+        options.value(editor.getValue());
+        onExecute();
+      }
+    });
+
     editor.commands.on("afterExec", function (e) {
       editor.session.getMode().$id = valueAccessor().mode(); // forces the id again because of Ace command internals
       if ((editor.session.getMode().$id == "ace/mode/hive" || editor.session.getMode().$id == "ace/mode/impala") && e.args == ".") {