Просмотр исходного кода

Merge pull request #6742 from overleaf/bg-cm6-chaos-monkey

[web] extend chaosmonkey for cm6

GitOrigin-RevId: d030952c9f0c8d3441321354f1ae61e5a6bc4d53
Brian Gough 4 лет назад
Родитель
Сommit
f23cc433a4
1 измененных файлов с 21 добавлено и 2 удалено
  1. 21 2
      services/web/frontend/js/ide/editor/Document.js

+ 21 - 2
services/web/frontend/js/ide/editor/Document.js

@@ -110,6 +110,8 @@ export default Document = (function () {
       if (editorDoc != null) {
       if (editorDoc != null) {
         editorDoc.off('change', this._checkAceConsistency)
         editorDoc.off('change', this._checkAceConsistency)
       }
       }
+      delete this.ace
+      this.clearChaosMonkey()
       return this.ide.$scope.$emit('document:closed', this.doc)
       return this.ide.$scope.$emit('document:closed', this.doc)
     }
     }
 
 
@@ -131,6 +133,8 @@ export default Document = (function () {
       if (this.cm != null) {
       if (this.cm != null) {
         this.cm.off('change', this._checkCMConsistency)
         this.cm.off('change', this._checkCMConsistency)
       }
       }
+      delete this.cm
+      this.clearChaosMonkey()
       return this.ide.$scope.$emit('document:closed', this.doc)
       return this.ide.$scope.$emit('document:closed', this.doc)
     }
     }
 
 
@@ -152,6 +156,8 @@ export default Document = (function () {
       if (this.cm6 != null) {
       if (this.cm6 != null) {
         this.cm6.off('change', this._checkCM6Consistency)
         this.cm6.off('change', this._checkCM6Consistency)
       }
       }
+      delete this.cm6
+      this.clearChaosMonkey()
       return this.ide.$scope.$emit('document:closed', this.doc)
       return this.ide.$scope.$emit('document:closed', this.doc)
     }
     }
 
 
@@ -335,7 +341,16 @@ export default Document = (function () {
         }
         }
         char = copy[0]
         char = copy[0]
         copy = copy.slice(1)
         copy = copy.slice(1)
-        this.ace.session.insert({ row: line, column: pos }, char)
+        if (this.ace) {
+          this.ace.session.insert({ row: line, column: pos }, char)
+        } else if (this.cm6) {
+          this.cm6.view.dispatch({
+            changes: {
+              from: Math.min(pos, this.cm6.view.state.doc.length),
+              insert: char,
+            },
+          })
+        }
         pos += 1
         pos += 1
         return (this._cm = setTimeout(
         return (this._cm = setTimeout(
           timer,
           timer,
@@ -346,7 +361,11 @@ export default Document = (function () {
     }
     }
 
 
     clearChaosMonkey() {
     clearChaosMonkey() {
-      return clearTimeout(this._cm) // pending ops bigger than this are always considered unsaved
+      const timer = this._cm
+      if (timer) {
+        delete this._cm
+        return clearTimeout(timer)
+      }
     }
     }
 
 
     pollSavedStatus() {
     pollSavedStatus() {