Bladeren bron

HUE-3454 [editor] Textarea height is not persisted

Also changed autogrow to change event and no chunks
Enrico Berti 9 jaren geleden
bovenliggende
commit
70384e4513
1 gewijzigde bestanden met toevoegingen van 18 en 13 verwijderingen
  1. 18 13
      desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

+ 18 - 13
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -1369,28 +1369,32 @@
       var $target = $(options.target);
       var $target = $(options.target);
       var $resizer = $(element);
       var $resizer = $(element);
 
 
-      var lastEditorHeight = 7;
+      var lastEditorSize = $.totalStorage('hue.editor.editor.size') || 128;
+      var editorHeight = Math.floor(lastEditorSize / 16);
+      $target.height(lastEditorSize);
+      var autoExpand = true;
 
 
-      var autoExpandTimeout = window.setInterval(function () {
-        var chunks = Math.floor((Math.max(ace().session.getLength(), 4) - lastEditorHeight) / 4);
-        if (chunks !== 0) {
+      ace().on('change', function () {
+        if (autoExpand) {
           var maxAutoLines = Math.floor(($(window).height() - 200) / 16);
           var maxAutoLines = Math.floor(($(window).height() - 200) / 16);
-          if (ace().session.getLength() < maxAutoLines) {
-            $target.height($target.height() + 64 * chunks);
-          }
-          else {
-            $target.height(maxAutoLines * 16); // height of maxAutoLines
+          if (ace().session.getLength() > editorHeight) {
+            if (ace().session.getLength() < maxAutoLines) {
+              $target.height((ace().session.getLength() + 1) * 16);
+            }
+            else {
+              $target.height(maxAutoLines * 16); // height of maxAutoLines
+            }
+            ace().resize();
+            editorHeight = ace().session.getLength();
           }
           }
-          ace().resize();
-          lastEditorHeight += 4 * chunks;
         }
         }
-      }, 300);
+      });
 
 
       $resizer.draggable({
       $resizer.draggable({
         axis: "y",
         axis: "y",
         start: options.onStart ? options.onStart : function(){},
         start: options.onStart ? options.onStart : function(){},
         drag: function (event, ui) {
         drag: function (event, ui) {
-          clearInterval(autoExpandTimeout);
+          autoExpand = false;
           var currentHeight = ui.offset.top - 120;
           var currentHeight = ui.offset.top - 120;
           $target.css("height", currentHeight + "px");
           $target.css("height", currentHeight + "px");
           ace().resize();
           ace().resize();
@@ -1400,6 +1404,7 @@
         stop: function (event, ui) {
         stop: function (event, ui) {
           ui.offset.top = 0;
           ui.offset.top = 0;
           ui.position.top = 0;
           ui.position.top = 0;
+          $.totalStorage('hue.editor.editor.size', $target.height());
           $(document).trigger("editorSizeChanged");
           $(document).trigger("editorSizeChanged");
         }
         }
       });
       });