Sfoglia il codice sorgente

HUE-6799 [editor] Save the cursor position with the snippet

Johan Ahlen 8 anni fa
parent
commit
dd87a0c

+ 19 - 6
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3590,19 +3590,26 @@
       var cursorChangePaused = false; // On change the cursor is also moved, this limits the calls while typing
 
       var lastStart;
+      var lastCursorPosition;
       var changeSelectionListener = self.editor.on('changeSelection', function () {
         if (cursorChangePaused) {
           return;
         }
         window.clearTimeout(changeThrottle);
         changeThrottle = window.setTimeout(function () {
+          var newCursorPosition = self.editor.getCursorPosition();
+          if (!lastCursorPosition || lastCursorPosition.row !== newCursorPosition.row || lastCursorPosition.column !== newCursorPosition.column) {
+            self.snippet.aceCursorPosition(newCursorPosition);
+            lastCursorPosition = newCursorPosition;
+          }
+
+          // The active statement is initially the top one in the selection, batch execution updates this.
           var newStart = self.editor.getSelectionRange().start;
-          if (lastStart && lastStart.row === newStart.row && lastStart.column === newStart.column) {
-            return;
+          if (!lastStart || lastStart.row !== newStart.row || lastStart.column !== newStart.column) {
+            window.clearTimeout(updateThrottle);
+            updateActiveStatement(true);
+            lastStart = newStart;
           }
-          window.clearTimeout(updateThrottle);
-          updateActiveStatement(true);
-          lastStart = newStart;
         }, 100);
       });
 
@@ -4116,7 +4123,6 @@
         processErrorsAndWarnings('error', newErrors);
       });
 
-
       var aceWarningsSub = snippet.aceWarnings.subscribe(function (newWarnings) {
         processErrorsAndWarnings('warning', newWarnings);
       });
@@ -4303,6 +4309,13 @@
         editor.off('input', inputListener);
       });
 
+      if (snippet.aceCursorPosition()) {
+        editor.moveCursorToPosition(snippet.aceCursorPosition());
+        window.setTimeout(function () {
+          editor.centerSelection();
+        }, 0);
+      }
+
       var focusListener = editor.on('focus', function () {
         initAutocompleters();
         snippet.inFocus(true);

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

@@ -272,6 +272,8 @@ var EditorViewModel = (function() {
     });
 
     // Ace stuff
+    self.aceCursorPosition = ko.observable(snippet.aceCursorPosition);
+
     var aceEditor = null;
 
     self.ace = function (newVal) {