Pārlūkot izejas kodu

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.
Alasdair Smith 8 gadi atpakaļ
vecāks
revīzija
b6a4bb74f8

+ 1 - 0
services/web/public/coffee/ide/editor/directives/aceEditor.coffee

@@ -516,6 +516,7 @@ define [
 
 
 				scope.$on '$destroy', () ->
 				scope.$on '$destroy', () ->
 					if scope.sharejsDoc?
 					if scope.sharejsDoc?
+						scope.$broadcast('changeEditor')
 						tearDownSpellCheck()
 						tearDownSpellCheck()
 						tearDownCursorPosition()
 						tearDownCursorPosition()
 						detachFromAce(scope.sharejsDoc)
 						detachFromAce(scope.sharejsDoc)

+ 7 - 3
services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee

@@ -3,12 +3,12 @@ define [], () ->
 		constructor: (@$scope, @adapter, @localStorage) ->
 		constructor: (@$scope, @adapter, @localStorage) ->
 			@$scope.$on 'editorInit', @jumpToPositionInNewDoc
 			@$scope.$on 'editorInit', @jumpToPositionInNewDoc
 
 
-			@$scope.$on 'beforeChangeDocument', () =>
-				@storeCursorPosition()
-				@storeFirstVisibleLine()
+			@$scope.$on 'beforeChangeDocument', @storePositionAndLine
 
 
 			@$scope.$on 'afterChangeDocument', @jumpToPositionInNewDoc
 			@$scope.$on 'afterChangeDocument', @jumpToPositionInNewDoc
 
 
+			@$scope.$on 'changeEditor', @storePositionAndLine
+
 			@$scope.$on "#{@$scope.name}:gotoLine", (e, line, column) =>
 			@$scope.$on "#{@$scope.name}:gotoLine", (e, line, column) =>
 				if line?
 				if line?
 					setTimeout () =>
 					setTimeout () =>
@@ -24,6 +24,10 @@ define [], () ->
 			@$scope.$on "#{@$scope.name}:clearSelection", (e) =>
 			@$scope.$on "#{@$scope.name}:clearSelection", (e) =>
 				@adapter.clearSelection()
 				@adapter.clearSelection()
 
 
+		storePositionAndLine: () =>
+			@storeCursorPosition()
+			@storeFirstVisibleLine()
+
 		jumpToPositionInNewDoc: () =>
 		jumpToPositionInNewDoc: () =>
 			@doc_id = @$scope.sharejsDoc?.doc_id
 			@doc_id = @$scope.sharejsDoc?.doc_id
 			setTimeout () =>
 			setTimeout () =>