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

Create cmEditor directive to connect to ShareJS

Alasdair Smith 8 лет назад
Родитель
Сommit
d15efc6fb6

+ 3 - 0
services/web/public/coffee/ide/editor/directives/aceEditor.coffee

@@ -428,6 +428,9 @@ define [
 					if rendererData?
 						rendererData.lineHeight = editor.renderer.lineHeight
 
+				scope.$on '$destroy', () ->
+					detachFromAce(scope.sharejsDoc)
+
 			template: """
 				<div class="ace-editor-wrapper">
 					<div

+ 32 - 0
services/web/public/coffee/ide/editor/directives/cmEditor.coffee

@@ -0,0 +1,32 @@
+define [
+  "base"
+], (App) ->
+  App.directive "cmEditor", () ->
+    return {
+      scope: {
+        sharejsDoc: "="
+      }
+
+      link: (scope, element, attrs) ->
+        cm = Frontend.richText.init(element.find('.cm-editor-wrapper')[0])
+
+        scope.$watch "sharejsDoc", (sharejsDoc, oldSharejsDoc) ->
+          if oldSharejsDoc?
+            detachFromCM(oldSharejsDoc)
+          if sharejsDoc?
+            attachToCM(sharejsDoc)
+
+        attachToCM = (sharejsDoc) ->
+          cm.setValue(sharejsDoc.getSnapshot())
+          sharejsDoc.attachToCM(cm)
+
+        detachFromCM = (sharejsDoc) ->
+          sharejsDoc.detachFromCM()
+
+        scope.$on 'destroy', () ->
+          detachFromCM(scope.sharejsDoc)
+
+      template: """
+        <div class="cm-editor-wrapper"></div>
+      """
+    }

+ 10 - 1
services/web/public/stylesheets/app/editor.less

@@ -75,8 +75,9 @@
 	top: 40px;
 }
 
-#editor {
+#editor, #editor-rich-text {
 	.full-size;
+	top: 40px; // TODO: replace with toolbar height var
 }
 
 .loading-screen {
@@ -190,6 +191,14 @@
 	}
 }
 
+.cm-editor-wrapper {
+	height: 100%;
+
+	.CodeMirror {
+		height: 100%;
+	}
+}
+
 // The internal components of the aceEditor directive
 .ace-editor-wrapper {
 	.full-size;