Browse Source

HUE-7855 [editor] Disable the editor auto-resize when running a saved query

Enrico Berti 7 năm trước cách đây
mục cha
commit
8c9487dda8

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

@@ -2144,9 +2144,10 @@
       var editorHeight = Math.floor(lastEditorSize / 16);
       $target.height(lastEditorSize);
       var autoExpand = true;
+      var draggedOnce = false;
 
       function throttleChange() {
-        if (autoExpand) {
+        if (autoExpand && !draggedOnce) {
           var maxAutoLines = Math.floor((($(window).height() - 80) / 2) / 16);
           var resized = false;
           if (ace().session.getLength() > editorHeight) {
@@ -2180,11 +2181,17 @@
         changeTimeout = window.setTimeout(throttleChange, 10)
       });
 
+      var setAutoExpandSubscription = huePubSub.subscribe('ace.set.autoexpand', function (options) {
+        if (ace().container.id === options.snippet.id()) {
+          autoExpand = options.autoExpand;
+        }
+      });
+
       $resizer.draggable({
         axis: "y",
         start: options.onStart ? options.onStart : function(){},
         drag: function (event, ui) {
-          autoExpand = false;
+          draggedOnce = true;
           var currentHeight = ui.offset.top + $contentPanel.scrollTop() - (125 + $execStatus.outerHeight(true) + $variables.outerHeight(true));
           $target.css("height", currentHeight + "px");
           ace().resize();
@@ -2199,6 +2206,10 @@
           $(document).trigger("editorSizeChanged");
         }
       });
+
+      ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
+        skipAutoExpandSubscription.remove();
+      });
     }
   };
 

+ 2 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1268,6 +1268,7 @@ var EditorViewModel = (function() {
       }
 
       if (self.ace()) {
+        huePubSub.publish('ace.set.autoexpand', { autoExpand: false, snippet: self });
         var selectionRange = self.ace().getSelectionRange();
         self.lastAceSelectionRowOffset(Math.min(selectionRange.start.row, selectionRange.end.row));
       }
@@ -1325,6 +1326,7 @@ var EditorViewModel = (function() {
         snippet: ko.mapping.toJSON(self.getContext())
       }, function (data) {
         self.statusForButtons('executed');
+        huePubSub.publish('ace.set.autoexpand', { autoExpand: true, snippet: self });
         stopLongOperationTimeout();
 
         if (vm.editorMode() && data.history_id) {