Extract rich text code to module

This commit is contained in:
Alasdair Smith 2018-03-21 13:24:38 +00:00
parent 1a0154c9ea
commit 3f8eda2223
4 changed files with 0 additions and 58 deletions

View file

@ -1,9 +1,7 @@
define [
"ide/editor/Document"
"ide/editor/directives/aceEditor"
"ide/editor/directives/cmEditor"
"ide/editor/controllers/SavingNotificationController"
"ide/editor/controllers/EditorToolbarController"
], (Document) ->
class EditorManager
constructor: (@ide, @$scope) ->

View file

@ -1,7 +0,0 @@
define [
"base"
"ide/editor/Document"
], (App, Document) ->
App.controller "EditorToolbarController", ($scope, ide) ->
$scope.toggleRichText = () ->
ide.editorManager.toggleRichText()

View file

@ -1,33 +0,0 @@
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) ->
scope.$applyAsync () ->
Frontend.richText.openDoc(cm, sharejsDoc.getSnapshot())
sharejsDoc.attachToCM(cm)
detachFromCM = (sharejsDoc) ->
sharejsDoc.detachFromCM()
scope.$on 'destroy', () ->
detachFromCM(scope.sharejsDoc)
template: """
<div class="cm-editor-wrapper"></div>
"""
}

View file

@ -1,16 +0,0 @@
import CodeMirror, { Doc } from 'codemirror'
export function init (rootEl) {
CodeMirror.defineMIME('application/x-tex', 'latex')
CodeMirror.defineMIME('application/x-latex', 'latex')
return CodeMirror(rootEl, {
mode: 'latex'
})
}
export function openDoc (cm, content) {
const newDoc = Doc(content, 'latex')
cm.swapDoc(newDoc)
return newDoc
}