mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Use events for updating cursor = big performance gain
This commit is contained in:
@@ -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)
|
||||
|
||||
+8
-6
@@ -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", {
|
||||
|
||||
Reference in New Issue
Block a user