mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Extract rich text code to module
This commit is contained in:
@@ -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) ->
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
define [
|
||||
"base"
|
||||
"ide/editor/Document"
|
||||
], (App, Document) ->
|
||||
App.controller "EditorToolbarController", ($scope, ide) ->
|
||||
$scope.toggleRichText = () ->
|
||||
ide.editorManager.toggleRichText()
|
||||
@@ -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>
|
||||
"""
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user