mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Use events for updating cursor = big performance gain
This commit is contained in:
parent
d9c8e5c1c2
commit
b0f43eab19
5 changed files with 17 additions and 18 deletions
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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", {
|
||||
|
|
Loading…
Reference in a new issue