diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index f408bc04e9..f925353041 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -54,7 +54,14 @@ block content include ./editor/file-tree .ui-layout-center - #editor(ace-editor, theme="'cobalt'", show-print-margin="false", sharejs-doc="editor.sharejs_doc", last-updated="editor.last_updated") + #editor( + ace-editor, + ng-show="!!editor.sharejs_doc" + theme="'cobalt'", + show-print-margin="false", + sharejs-doc="editor.sharejs_doc", + last-updated="editor.last_updated" + ) //- #loadingScreen //- h3 Loading... diff --git a/services/web/public/coffee/app/ide/editor/EditorManager.coffee b/services/web/public/coffee/app/ide/editor/EditorManager.coffee index cea0702093..63d36c4b6c 100644 --- a/services/web/public/coffee/app/ide/editor/EditorManager.coffee +++ b/services/web/public/coffee/app/ide/editor/EditorManager.coffee @@ -9,8 +9,34 @@ define [ last_updated: null } + @$scope.$on "entity:selected", (event, entity) => + if (entity.type == "doc") + @openDoc(entity) + + initialized = false + @$scope.$on "file-tree:initialized", () => + if !initialized + initialized = true + @autoOpenDoc() + + autoOpenDoc: () -> + open_doc_id = + $.localStorage("doc.open_id.#{@$scope.project_id}") or + @$scope.project.rootDoc_id + return if !open_doc_id? + doc = @ide.fileTreeManager.findEntityById(open_doc_id) + return if !doc? + @openDoc(doc) + openDoc: (doc, options = {}) -> - # TODO: Don't open if already open + console.log "Trying to open doc", doc.id + return if doc.id == @open_doc_id + @open_doc_id = doc.id + console.log "Actually opening doc", doc.id + + $.localStorage "doc.open_id.#{@$scope.project_id}", doc.id + @ide.fileTreeManager.selectEntity(doc) + @_openNewDocument doc, (error, sharejs_doc) => if error? @ide.showGenericServerErrorMessage() diff --git a/services/web/public/coffee/app/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/app/ide/editor/directives/aceEditor.coffee index 3ce3003450..0385cbd8f1 100644 --- a/services/web/public/coffee/app/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/app/ide/editor/directives/aceEditor.coffee @@ -61,9 +61,7 @@ define [ session.setMode(new LatexMode()) doc = session.getDocument() - console.log "Document", doc doc.on "change", () -> - console.log "DOC CHANGE" scope.$apply () -> scope.lastUpdated = new Date() @@ -85,8 +83,8 @@ define [ sharejs_doc.attachToAce(editor) detachFromAce = (sharejs_doc) -> - old_sharejs_doc.detachFromAce() - old_sharejs_doc.off "remoteop.recordForUndo" + sharejs_doc.detachFromAce() + sharejs_doc.off "remoteop.recordForUndo" template: """