diff --git a/services/web/public/coffee/app/ide/editor/annotations/AnnotationsManager.coffee b/services/web/public/coffee/app/ide/editor/annotations/AnnotationsManager.coffee index f8839ac025..2d10114edb 100644 --- a/services/web/public/coffee/app/ide/editor/annotations/AnnotationsManager.coffee +++ b/services/web/public/coffee/app/ide/editor/annotations/AnnotationsManager.coffee @@ -30,14 +30,12 @@ define [ @showAnnotationLabels(position) redrawAnnotations: () -> - console.log "REDRAWING ANNOTATIONS" @_clearMarkers() @_clearLabels() for annotation in @$scope.annotations or [] do (annotation) => colorScheme = @_getColorScheme(annotation.hue) - console.log "DRAWING ANNOTATION", annotation, colorScheme if annotation.cursor? @labels.push { text: annotation.text @@ -85,9 +83,6 @@ define [ left = coords.pageX - console.log "TOP BOTTOM", top, bottom - - @$scope.annotationLabel = { show: true left: left diff --git a/services/web/public/coffee/app/ide/editor/cursor-position/CursorPositionManager.coffee b/services/web/public/coffee/app/ide/editor/cursor-position/CursorPositionManager.coffee new file mode 100644 index 0000000000..e1346ef9ee --- /dev/null +++ b/services/web/public/coffee/app/ide/editor/cursor-position/CursorPositionManager.coffee @@ -0,0 +1,33 @@ +define [], () -> + class CursorPositionManager + constructor: (@$scope, @editor, @element) -> + + @editor.on "changeSession", (e) => + e.session.on "changeScrollTop", (e) => + @onScrollTopChange(e) + + e.session.selection.on 'changeCursor', (e) => + @onCursorChange(e) + + @gotoStoredPosition() + + onScrollTopChange: (event) -> + if !@ignoreCursorPositionChanges and doc_id = @$scope.sharejsDoc?.doc_id + docPosition = $.localStorage("doc.position.#{doc_id}") || {} + docPosition.scrollTop = @editor.getSession().getScrollTop() + $.localStorage("doc.position.#{doc_id}", docPosition) + + onCursorChange: (event) -> + if !@ignoreCursorPositionChanges and doc_id = @$scope.sharejsDoc?.doc_id + docPosition = $.localStorage("doc.position.#{doc_id}") || {} + docPosition.cursorPosition = @editor.getCursorPosition() + $.localStorage("doc.position.#{doc_id}", docPosition) + + gotoStoredPosition: () -> + doc_id = @$scope.sharejsDoc?.doc_id + return if !doc_id? + pos = $.localStorage("doc.position.#{doc_id}") || {} + @ignoreCursorPositionChanges = true + @editor.moveCursorToPosition(pos.cursorPosition or {row: 0, column: 0}) + @editor.getSession().setScrollTop(pos.scrollTop or 0) + delete @ignoreCursorPositionChanges \ No newline at end of file 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 0d668dafa9..3c3c601d91 100644 --- a/services/web/public/coffee/app/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/app/ide/editor/directives/aceEditor.coffee @@ -5,11 +5,12 @@ define [ "ide/editor/auto-complete/AutoCompleteManager" "ide/editor/spell-check/SpellCheckManager" "ide/editor/annotations/AnnotationsManager" + "ide/editor/cursor-position/CursorPositionManager" "ace/keyboard/vim" "ace/keyboard/emacs" "ace/mode/latex" "ace/edit_session" -], (App, Ace, UndoManager, AutoCompleteManager, SpellCheckManager, AnnotationsManager) -> +], (App, Ace, UndoManager, AutoCompleteManager, SpellCheckManager, AnnotationsManager, CursorPositionManager) -> LatexMode = require("ace/mode/latex").Mode EditSession = require('ace/edit_session').EditSession @@ -37,12 +38,13 @@ define [ else @$originalApply(fn); - editor = Ace.edit(element.find(".ace-editor-body")[0]) + window.editor = editor = Ace.edit(element.find(".ace-editor-body")[0]) - autoCompleteManager = new AutoCompleteManager(scope, editor, element) - spellCheckManager = new SpellCheckManager(scope, editor, element) - undoManager = new UndoManager(scope, editor, element) - annotationsManagaer = new AnnotationsManager(scope, editor, element) + autoCompleteManager = new AutoCompleteManager(scope, editor, element) + spellCheckManager = new SpellCheckManager(scope, editor, element) + undoManager = new UndoManager(scope, editor, element) + annotationsManager = new AnnotationsManager(scope, editor, element) + cursorPositionManager = new CursorPositionManager(scope, editor, element) # Prevert Ctrl|Cmd-S from triggering save dialog editor.commands.addCommand @@ -91,7 +93,7 @@ define [ session.setMode(new LatexMode()) autoCompleteManager.bindToSession(session) - annotationsManagaer.redrawAnnotations() + annotationsManager.redrawAnnotations() doc = session.getDocument() doc.on "change", () -> @@ -103,6 +105,8 @@ define [ sharejs_doc.attachToAce(editor) + editor.focus() + detachFromAce = (sharejs_doc) -> sharejs_doc.detachFromAce() sharejs_doc.off "remoteop.recordForUndo" diff --git a/services/web/public/coffee/app/ide/online-users/OnlineUsersManager.coffee b/services/web/public/coffee/app/ide/online-users/OnlineUsersManager.coffee index 2f382cc805..4bb3a4cafa 100644 --- a/services/web/public/coffee/app/ide/online-users/OnlineUsersManager.coffee +++ b/services/web/public/coffee/app/ide/online-users/OnlineUsersManager.coffee @@ -7,19 +7,16 @@ define [ @$scope.onlineUserCursorAnnotations = {} @$scope.$watch "editor.cursorPosition", (position) => - console.log "CURSOR POSITION UPDATE", position if position? @sendCursorPositionUpdate() @ide.socket.on "clientTracking.clientUpdated", (client) => - console.log "REMOTE CURSOR POSITION UPDATE", client if client.id != @ide.socket.socket.sessionid # Check it's not me! @$scope.$apply () => @$scope.onlineUsers[client.id] = client @updateCursorHighlights() @ide.socket.on "clientTracking.clientDisconnected", (client_id) => - console.log "CLIENT DISCONNECTED", client_id @$scope.$apply () => delete @$scope.onlineUsers[client_id] @updateCursorHighlights() @@ -42,7 +39,6 @@ define [ UPDATE_INTERVAL: 500 sendCursorPositionUpdate: () -> if !@cursorUpdateTimeout? - console.log "CREATING DELAYED UPDATED" @cursorUpdateTimeout = setTimeout ()=> position = @$scope.editor.cursorPosition doc_id = @$scope.editor.open_doc_id @@ -55,8 +51,6 @@ define [ delete @cursorUpdateTimeout , @UPDATE_INTERVAL - else - console.log "NOT UPDATING" OWN_HUE: 200 # We will always appear as this color to ourselves ANONYMOUS_HUE: 100