Create cmEditor directive to connect to ShareJS

This commit is contained in:
Alasdair Smith
2018-01-19 16:28:56 +00:00
parent b9327cb2d4
commit d15efc6fb6
3 changed files with 45 additions and 1 deletions
@@ -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
@@ -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>
"""
}
@@ -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;