From da77c067744b01f6a87286717fda054b341afe58 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Thu, 5 Jul 2018 17:37:53 +0100 Subject: [PATCH] Refactor saving cursor position to not use Ace event This is will help with triggering CM correctly --- .../coffee/ide/editor/directives/aceEditor.coffee | 3 ++- .../cursor-position/CursorPositionManager.coffee | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index b92e7bfb0c..fadc5a4a03 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -308,6 +308,8 @@ define [ editor.renderer.updateFontSize() scope.$watch "sharejsDoc", (sharejs_doc, old_sharejs_doc) -> + cursorPositionManager.onBeforeSessionChange(!!old_sharejs_doc) + if old_sharejs_doc? detachFromAce(old_sharejs_doc) @@ -382,7 +384,6 @@ define [ editor.off 'nativecontextmenu', spellCheckManager.onContextMenu onSessionChangeForCursorPosition = (e) -> - cursorPositionManager.onSessionChange(e) e.oldSession?.selection.off 'changeCursor', cursorPositionManager.onCursorChange e.session.selection.on 'changeCursor', cursorPositionManager.onCursorChange diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee index b7ba730507..57acb81546 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee @@ -19,9 +19,9 @@ define [], () -> init: () -> @emitCursorUpdateEvent() - onSessionChange: (e) => - if e.oldSession? - @storeCursorPosition(e.oldSession) + onBeforeSessionChange: (hasPrevSession = false) => + if hasPrevSession + @storeCursorPosition() @storeFirstVisibleLine() @doc_id = @$scope.sharejsDoc?.doc_id @@ -30,8 +30,8 @@ define [], () -> @gotoStoredPosition() , 0 - onUnload: (session) => - @storeCursorPosition(session) + onUnload: () => + @storeCursorPosition() @storeFirstVisibleLine() onCursorChange: () => @@ -43,10 +43,10 @@ define [], () -> docPosition.firstVisibleLine = @adapter.getEditorScrollPosition() @localStorage("doc.position.#{@doc_id}", docPosition) - storeCursorPosition: (session) -> + storeCursorPosition: () -> if @doc_id? docPosition = @localStorage("doc.position.#{@doc_id}") || {} - docPosition.cursorPosition = @adapter.getCursorForSession(session) + docPosition.cursorPosition = @adapter.getCursor() @localStorage("doc.position.#{@doc_id}", docPosition) emitCursorUpdateEvent: () ->