Ver código fonte

Dynamically expand editor height as needed

Andrew Kane 9 anos atrás
pai
commit
6ef1125a50
1 arquivos alterados com 15 adições e 2 exclusões
  1. 15 2
      app/views/blazer/queries/_form.html.erb

+ 15 - 2
app/views/blazer/queries/_form.html.erb

@@ -61,12 +61,25 @@
     name: 'run',
     bindKey: {win: 'Ctrl-Enter',  mac: 'Command-Enter'},
     exec: function(editor) {
-        $("#run").click();
+      $("#run").click();
     },
     readOnly: false // false if this command should not apply in readOnly mode
   });
 
-  editor.resize();
+ // http://stackoverflow.com/questions/11584061/
+ function adjustHeight() {
+    var lines = editor.getSession().getScreenLength();
+    if (lines < 9) {
+      lines = 9;
+    }
+
+    var newHeight = (lines + 1) * 16;
+    $("#editor").height(newHeight.toString() + "px");
+    editor.resize();
+  };
+
+  editor.getSession().on("change", adjustHeight);
+  adjustHeight();
   $("#editor").show();
   editor.focus();