From b6a4bb74f89da700d8165a39c98859ce8e8c618e Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 10 Sep 2018 11:02:08 +0100 Subject: [PATCH] Store cursor & line position when switching editor When tearing down the source editor, we need to store the updated cursor position, so that the position can be moved to when opening the rich text editor. --- .../coffee/ide/editor/directives/aceEditor.coffee | 1 + .../cursor-position/CursorPositionManager.coffee | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index e3ab0b29be..015a4e65ee 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -516,6 +516,7 @@ define [ scope.$on '$destroy', () -> if scope.sharejsDoc? + scope.$broadcast('changeEditor') tearDownSpellCheck() tearDownCursorPosition() detachFromAce(scope.sharejsDoc) 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 bb957f8cf6..764fcb1c98 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 @@ -3,12 +3,12 @@ define [], () -> constructor: (@$scope, @adapter, @localStorage) -> @$scope.$on 'editorInit', @jumpToPositionInNewDoc - @$scope.$on 'beforeChangeDocument', () => - @storeCursorPosition() - @storeFirstVisibleLine() + @$scope.$on 'beforeChangeDocument', @storePositionAndLine @$scope.$on 'afterChangeDocument', @jumpToPositionInNewDoc + @$scope.$on 'changeEditor', @storePositionAndLine + @$scope.$on "#{@$scope.name}:gotoLine", (e, line, column) => if line? setTimeout () => @@ -24,6 +24,10 @@ define [], () -> @$scope.$on "#{@$scope.name}:clearSelection", (e) => @adapter.clearSelection() + storePositionAndLine: () => + @storeCursorPosition() + @storeFirstVisibleLine() + jumpToPositionInNewDoc: () => @doc_id = @$scope.sharejsDoc?.doc_id setTimeout () =>