James Allen 12 лет назад
Родитель
Сommit
51d0026b74

+ 1 - 1
services/web/public/coffee/ide/editor/EditorManager.coffee

@@ -38,7 +38,7 @@ define [
 
 			done = () =>
 				if options.gotoLine?
-					@$scope.editor.gotoLine = options.gotoLine
+					@$scope.$broadcast "editor:gotoLine", options.gotoLine
 			
 			if doc.id == @$scope.editor.open_doc_id and !options.forceReopen
 				@$scope.$apply () =>

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

@@ -46,8 +46,8 @@ define [
 
 				scope.name = attrs.aceEditor
 
-				# autoCompleteManager   = new AutoCompleteManager(scope, editor, element)
-				# spellCheckManager     = new SpellCheckManager(scope, editor, element)
+				autoCompleteManager   = new AutoCompleteManager(scope, editor, element)
+				spellCheckManager     = new SpellCheckManager(scope, editor, element)
 				undoManager           = new UndoManager(scope, editor, element)
 				highlightsManager     = new HighlightsManager(scope, editor, element)
 				cursorPositionManager = new CursorPositionManager(scope, editor, element)

+ 27 - 25
services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee

@@ -3,47 +3,49 @@ define [], () ->
 		constructor: (@$scope, @editor, @element) ->
 
 			@editor.on "changeSession", (e) =>
-				e.session.on "changeScrollTop", (e) =>
-					@onScrollTopChange(e)
+				if e.oldSession?
+					@storeCursorPosition(e.oldSession)
+					@storeScrollTopPosition(e.oldSession)
+
+				@doc_id = @$scope.sharejsDoc?.doc_id
 
 				e.session.selection.on 'changeCursor', (e) =>
-					@onCursorChange(e)
+					@emitCursorUpdateEvent(e)
+
+				setTimeout () =>
+					@gotoStoredPosition()
+				, 0
 
-				@gotoStoredPosition()
+			$(window).on "unload", () =>
+				@storeCursorPosition(@editor.getSession())
+				@storeScrollTopPosition(@editor.getSession())
 
-			@$scope.$watch "gotoLine", (value) =>
+			@$scope.$on "#{@$scope.name}:gotoLine", (editor, value) =>
 				console.log "Going to line", value
 				if value?
 					setTimeout () =>
 						@gotoLine(value)
-						@$scope.$apply () =>
-							@$scope.gotoLine = null
 					, 0
 
-		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)
+		storeScrollTopPosition: (session) ->
+			if @doc_id?
+				docPosition = $.localStorage("doc.position.#{@doc_id}") || {}
+				docPosition.scrollTop = session.getScrollTop()
+				$.localStorage("doc.position.#{@doc_id}", docPosition)
+
+		storeCursorPosition: (session) ->
+			if @doc_id?
+				docPosition = $.localStorage("doc.position.#{@doc_id}") || {}
+				docPosition.cursorPosition = session.selection.getCursor()
+				$.localStorage("doc.position.#{@doc_id}", docPosition)
 			
-		onCursorChange: (event) ->
-			@storeCursorPosition()
-			@emitCursorUpdateEvent()
-
-		storeCursorPosition: () ->
-			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)
-
 		emitCursorUpdateEvent: () ->
 			cursor = @editor.getCursorPosition()
 			@$scope.$emit "cursor:#{@$scope.name}:update", cursor
 
 		gotoStoredPosition: () ->
-			doc_id = @$scope.sharejsDoc?.doc_id
-			return if !doc_id?
-			pos = $.localStorage("doc.position.#{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)

+ 0 - 4
services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellCheckManager.coffee

@@ -29,8 +29,6 @@ define [
 			$(document).on "click", (e) =>
 				@closeContextMenu(e)
 				return true
-			# $(document).on "contextmenu", (e) =>
-			# 	@closeContextMenu(e)
 
 			@$scope.replaceWord = (highlight, suggestion) =>
 				@replaceWord(highlight, suggestion)
@@ -39,13 +37,11 @@ define [
 				@learnWord(highlight)
 
 		runFullCheck: () ->
-			console.log "Running full check"
 			@highlightedWordManager.clearRows()
 			if @$scope.spellCheckLanguage and @$scope.spellCheckLanguage != ""
 				@runSpellCheck()
 
 		runCheckOnChange: (e) ->
-			console.log "Checking change", e.data
 			if @$scope.spellCheckLanguage and @$scope.spellCheckLanguage != ""
 				@highlightedWordManager.applyChange(e.data)
 				@markLinesAsUpdated(e.data)