mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-15 04:24:52 +00:00
Restore cursor position:
This commit is contained in:
parent
afb953a489
commit
7e70dc9afc
4 changed files with 44 additions and 18 deletions
|
@ -30,14 +30,12 @@ define [
|
|||
@showAnnotationLabels(position)
|
||||
|
||||
redrawAnnotations: () ->
|
||||
console.log "REDRAWING ANNOTATIONS"
|
||||
@_clearMarkers()
|
||||
@_clearLabels()
|
||||
|
||||
for annotation in @$scope.annotations or []
|
||||
do (annotation) =>
|
||||
colorScheme = @_getColorScheme(annotation.hue)
|
||||
console.log "DRAWING ANNOTATION", annotation, colorScheme
|
||||
if annotation.cursor?
|
||||
@labels.push {
|
||||
text: annotation.text
|
||||
|
@ -85,9 +83,6 @@ define [
|
|||
|
||||
left = coords.pageX
|
||||
|
||||
console.log "TOP BOTTOM", top, bottom
|
||||
|
||||
|
||||
@$scope.annotationLabel = {
|
||||
show: true
|
||||
left: left
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
define [], () ->
|
||||
class CursorPositionManager
|
||||
constructor: (@$scope, @editor, @element) ->
|
||||
|
||||
@editor.on "changeSession", (e) =>
|
||||
e.session.on "changeScrollTop", (e) =>
|
||||
@onScrollTopChange(e)
|
||||
|
||||
e.session.selection.on 'changeCursor', (e) =>
|
||||
@onCursorChange(e)
|
||||
|
||||
@gotoStoredPosition()
|
||||
|
||||
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)
|
||||
|
||||
onCursorChange: (event) ->
|
||||
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)
|
||||
|
||||
gotoStoredPosition: () ->
|
||||
doc_id = @$scope.sharejsDoc?.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)
|
||||
delete @ignoreCursorPositionChanges
|
|
@ -5,11 +5,12 @@ define [
|
|||
"ide/editor/auto-complete/AutoCompleteManager"
|
||||
"ide/editor/spell-check/SpellCheckManager"
|
||||
"ide/editor/annotations/AnnotationsManager"
|
||||
"ide/editor/cursor-position/CursorPositionManager"
|
||||
"ace/keyboard/vim"
|
||||
"ace/keyboard/emacs"
|
||||
"ace/mode/latex"
|
||||
"ace/edit_session"
|
||||
], (App, Ace, UndoManager, AutoCompleteManager, SpellCheckManager, AnnotationsManager) ->
|
||||
], (App, Ace, UndoManager, AutoCompleteManager, SpellCheckManager, AnnotationsManager, CursorPositionManager) ->
|
||||
LatexMode = require("ace/mode/latex").Mode
|
||||
EditSession = require('ace/edit_session').EditSession
|
||||
|
||||
|
@ -37,12 +38,13 @@ define [
|
|||
else
|
||||
@$originalApply(fn);
|
||||
|
||||
editor = Ace.edit(element.find(".ace-editor-body")[0])
|
||||
window.editor = editor = Ace.edit(element.find(".ace-editor-body")[0])
|
||||
|
||||
autoCompleteManager = new AutoCompleteManager(scope, editor, element)
|
||||
spellCheckManager = new SpellCheckManager(scope, editor, element)
|
||||
undoManager = new UndoManager(scope, editor, element)
|
||||
annotationsManagaer = new AnnotationsManager(scope, editor, element)
|
||||
autoCompleteManager = new AutoCompleteManager(scope, editor, element)
|
||||
spellCheckManager = new SpellCheckManager(scope, editor, element)
|
||||
undoManager = new UndoManager(scope, editor, element)
|
||||
annotationsManager = new AnnotationsManager(scope, editor, element)
|
||||
cursorPositionManager = new CursorPositionManager(scope, editor, element)
|
||||
|
||||
# Prevert Ctrl|Cmd-S from triggering save dialog
|
||||
editor.commands.addCommand
|
||||
|
@ -91,7 +93,7 @@ define [
|
|||
session.setMode(new LatexMode())
|
||||
|
||||
autoCompleteManager.bindToSession(session)
|
||||
annotationsManagaer.redrawAnnotations()
|
||||
annotationsManager.redrawAnnotations()
|
||||
|
||||
doc = session.getDocument()
|
||||
doc.on "change", () ->
|
||||
|
@ -103,6 +105,8 @@ define [
|
|||
|
||||
sharejs_doc.attachToAce(editor)
|
||||
|
||||
editor.focus()
|
||||
|
||||
detachFromAce = (sharejs_doc) ->
|
||||
sharejs_doc.detachFromAce()
|
||||
sharejs_doc.off "remoteop.recordForUndo"
|
||||
|
|
|
@ -7,19 +7,16 @@ define [
|
|||
@$scope.onlineUserCursorAnnotations = {}
|
||||
|
||||
@$scope.$watch "editor.cursorPosition", (position) =>
|
||||
console.log "CURSOR POSITION UPDATE", position
|
||||
if position?
|
||||
@sendCursorPositionUpdate()
|
||||
|
||||
@ide.socket.on "clientTracking.clientUpdated", (client) =>
|
||||
console.log "REMOTE CURSOR POSITION UPDATE", client
|
||||
if client.id != @ide.socket.socket.sessionid # Check it's not me!
|
||||
@$scope.$apply () =>
|
||||
@$scope.onlineUsers[client.id] = client
|
||||
@updateCursorHighlights()
|
||||
|
||||
@ide.socket.on "clientTracking.clientDisconnected", (client_id) =>
|
||||
console.log "CLIENT DISCONNECTED", client_id
|
||||
@$scope.$apply () =>
|
||||
delete @$scope.onlineUsers[client_id]
|
||||
@updateCursorHighlights()
|
||||
|
@ -42,7 +39,6 @@ define [
|
|||
UPDATE_INTERVAL: 500
|
||||
sendCursorPositionUpdate: () ->
|
||||
if !@cursorUpdateTimeout?
|
||||
console.log "CREATING DELAYED UPDATED"
|
||||
@cursorUpdateTimeout = setTimeout ()=>
|
||||
position = @$scope.editor.cursorPosition
|
||||
doc_id = @$scope.editor.open_doc_id
|
||||
|
@ -55,8 +51,6 @@ define [
|
|||
|
||||
delete @cursorUpdateTimeout
|
||||
, @UPDATE_INTERVAL
|
||||
else
|
||||
console.log "NOT UPDATING"
|
||||
|
||||
OWN_HUE: 200 # We will always appear as this color to ourselves
|
||||
ANONYMOUS_HUE: 100
|
||||
|
|
Loading…
Reference in a new issue