Use events for updating cursor = big performance gain

This commit is contained in:
James Allen 2014-07-09 15:38:38 +01:00
parent d9c8e5c1c2
commit b0f43eab19
5 changed files with 17 additions and 18 deletions

View file

@ -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",

View file

@ -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",

View file

@ -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)

View file

@ -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?

View file

@ -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", {