Bläddra i källkod

Merge pull request #1 from nickelser/master

make editor bigger
Andrew Kane 10 år sedan
förälder
incheckning
1939fae1a7

+ 5 - 1
app/assets/stylesheets/blazer/application.css

@@ -58,9 +58,13 @@ input.search:focus {
 
 #editor {
   display: none;
-  height: 100px;
+  height: 175px;
 }
 
 .ace_print-margin-layer {
   display: none;
 }
+
+.ace_gutter-cell.error {
+  background-color: red;
+}

+ 33 - 3
app/views/blazer/queries/_form.html.erb

@@ -48,19 +48,49 @@
     enableSnippets: false,
     enableLiveAutocompletion: false,
     highlightActiveLine: false,
-    fontSize: 12
+    fontSize: 12,
+    minLines: 10
   });
-  editor.renderer.setShowGutter(false);
+  editor.renderer.setShowGutter(true);
   editor.renderer.setPrintMarginColumn(false);
   editor.renderer.setPadding(10);
   editor.getSession().setUseWrapMode(true);
+  editor.commands.addCommand({
+    name: 'run',
+    bindKey: {win: 'Ctrl-Enter',  mac: 'Command-Enter'},
+    exec: function(editor) {
+        $("#run").click();
+    },
+    readOnly: false // false if this command should not apply in readOnly mode
+  });
+
+  editor.resize();
   $("#editor").show();
+  editor.focus();
 
-  $("#run").click( function (e) {
+  var error_line = null;
+
+  $("#run").click(function (e) {
     e.preventDefault();
+
+    if (error_line) {
+      editor.getSession().removeGutterDecoration(error_line - 1, "error");
+      error_line = null;
+    }
+
     $("#results").html('<p class="text-muted">Loading...</p>');
     $.post("<%= run_queries_path %>", {statement: editor.getValue()}, function (data) {
       $("#results").html(data);
+
+      error_line = /LINE (\d+)/g.exec($("#results").find('.alert-danger').text());
+
+      if (error_line) {
+        error_line = parseInt(error_line[1], 10);
+        editor.getSession().addGutterDecoration(error_line - 1, "error");
+        editor.scrollToLine(error_line, true, true, function () {});
+        editor.gotoLine(error_line, 0, true);
+        editor.focus();
+      }
     });
   });