瀏覽代碼

HUE-7504 [editor] Prevent an infinite loop when changing the snippet type

Changing the type would initialize the aceEditor binding which in turn would update the ace observable on the snippet causing the editor to initialize over and over again.
Johan Ahlen 8 年之前
父節點
當前提交
1458daa
共有 1 個文件被更改,包括 10 次插入5 次删除
  1. 10 5
      desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

+ 10 - 5
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -272,12 +272,17 @@ var EditorViewModel = (function() {
     });
 
     // Ace stuff
-    self.ace = ko.observable(null);
-    self.ace.subscribe(function () {
-      if (!vm.isPresentationMode()) {
-        self.ace().focus();
+    var aceEditor = null;
+
+    self.ace = function (newVal) {
+      if (newVal) {
+        aceEditor = newVal;
+        if (!vm.isPresentationMode()) {
+          aceEditor.focus();
+        }
       }
-    });
+      return aceEditor
+    };
     self.errors = ko.observableArray([]);
 
     self.aceErrorsHolder = ko.observableArray([]);