Просмотр исходного кода

Use events for updating cursor = big performance gain

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

+ 1 - 1
services/web/app/views/project/editor/editor.jade

@@ -11,7 +11,7 @@ div.full-size(
 			|   Loading...
 
 		#editor(
-			ace-editor,
+			ace-editor="editor",
 			ng-show="!!editor.sharejs_doc && !editor.opening"
 			theme="settings.theme",
 			keybindings="settings.mode",

+ 1 - 1
services/web/app/views/project/editor/track-changes.jade

@@ -82,7 +82,7 @@ div#trackChanges(ng-show="ui.view == 'track-changes'")
 
 	.diff.full-size(ng-controller="TrackChangesDiffController")
 		.diff-editor.hide-ace-cursor(
-			ace-editor,
+			ace-editor="track-changes",
 			ng-show="!!trackChanges.diff && !trackChanges.diff.loading && !trackChanges.diff.deleted",
 			theme="settings.theme",
 			font-size="settings.fontSize",

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

@@ -43,11 +43,11 @@ define [
 						@$originalApply(fn);
 
 				editor = Ace.edit(element.find(".ace-editor-body")[0])
-				window.editors ||= []
-				window.editors.push editor
 
-				autoCompleteManager   = new AutoCompleteManager(scope, editor, element)
-				spellCheckManager     = new SpellCheckManager(scope, editor, element)
+				scope.name = attrs.aceEditor
+
+				# 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)

+ 8 - 6
services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee

@@ -11,12 +11,6 @@ define [], () ->
 
 				@gotoStoredPosition()
 
-			@editor.on "changeSelection", () =>
-				cursor = @editor.getCursorPosition()
-				@$scope.$apply () =>
-					if @$scope.cursorPosition?
-						@$scope.cursorPosition = cursor
-
 			@$scope.$watch "gotoLine", (value) =>
 				console.log "Going to line", value
 				if value?
@@ -33,11 +27,19 @@ define [], () ->
 				$.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?

+ 3 - 6
services/web/public/coffee/ide/online-users/OnlineUsersManager.coffee

@@ -6,9 +6,8 @@ define [
 			@$scope.onlineUsers = {}
 			@$scope.onlineUserCursorHighlights = {}
 
-			@$scope.$watch "editor.cursorPosition", (position) =>
-				if position?
-					@sendCursorPositionUpdate()
+			@$scope.$on "cursor:editor:update", (event, position) =>
+				@sendCursorPositionUpdate(position)
 
 			@ide.socket.on "clientTracking.clientUpdated", (client) =>
 				if client.id != @ide.socket.socket.sessionid # Check it's not me!
@@ -37,11 +36,9 @@ define [
 				}
 
 		UPDATE_INTERVAL: 500
-		sendCursorPositionUpdate: () ->
-			console.log "SENDING CURSOR POSITION UPDATE", @$scope.editor.cursorPosition
+		sendCursorPositionUpdate: (position) ->
 			if !@cursorUpdateTimeout?
 				@cursorUpdateTimeout = setTimeout ()=>
-					position = @$scope.editor.cursorPosition
 					doc_id   = @$scope.editor.open_doc_id
 
 					@ide.socket.emit "clientTracking.updatePosition", {