Refactor saving cursor position to not use Ace event

This is will help with triggering CM correctly
This commit is contained in:
Alasdair Smith 2018-07-05 17:37:53 +01:00
parent ba9fa9a0be
commit da77c06774
2 changed files with 9 additions and 8 deletions

View file

@ -308,6 +308,8 @@ define [
editor.renderer.updateFontSize() editor.renderer.updateFontSize()
scope.$watch "sharejsDoc", (sharejs_doc, old_sharejs_doc) -> scope.$watch "sharejsDoc", (sharejs_doc, old_sharejs_doc) ->
cursorPositionManager.onBeforeSessionChange(!!old_sharejs_doc)
if old_sharejs_doc? if old_sharejs_doc?
detachFromAce(old_sharejs_doc) detachFromAce(old_sharejs_doc)
@ -382,7 +384,6 @@ define [
editor.off 'nativecontextmenu', spellCheckManager.onContextMenu editor.off 'nativecontextmenu', spellCheckManager.onContextMenu
onSessionChangeForCursorPosition = (e) -> onSessionChangeForCursorPosition = (e) ->
cursorPositionManager.onSessionChange(e)
e.oldSession?.selection.off 'changeCursor', cursorPositionManager.onCursorChange e.oldSession?.selection.off 'changeCursor', cursorPositionManager.onCursorChange
e.session.selection.on 'changeCursor', cursorPositionManager.onCursorChange e.session.selection.on 'changeCursor', cursorPositionManager.onCursorChange

View file

@ -19,9 +19,9 @@ define [], () ->
init: () -> init: () ->
@emitCursorUpdateEvent() @emitCursorUpdateEvent()
onSessionChange: (e) => onBeforeSessionChange: (hasPrevSession = false) =>
if e.oldSession? if hasPrevSession
@storeCursorPosition(e.oldSession) @storeCursorPosition()
@storeFirstVisibleLine() @storeFirstVisibleLine()
@doc_id = @$scope.sharejsDoc?.doc_id @doc_id = @$scope.sharejsDoc?.doc_id
@ -30,8 +30,8 @@ define [], () ->
@gotoStoredPosition() @gotoStoredPosition()
, 0 , 0
onUnload: (session) => onUnload: () =>
@storeCursorPosition(session) @storeCursorPosition()
@storeFirstVisibleLine() @storeFirstVisibleLine()
onCursorChange: () => onCursorChange: () =>
@ -43,10 +43,10 @@ define [], () ->
docPosition.firstVisibleLine = @adapter.getEditorScrollPosition() docPosition.firstVisibleLine = @adapter.getEditorScrollPosition()
@localStorage("doc.position.#{@doc_id}", docPosition) @localStorage("doc.position.#{@doc_id}", docPosition)
storeCursorPosition: (session) -> storeCursorPosition: () ->
if @doc_id? if @doc_id?
docPosition = @localStorage("doc.position.#{@doc_id}") || {} docPosition = @localStorage("doc.position.#{@doc_id}") || {}
docPosition.cursorPosition = @adapter.getCursorForSession(session) docPosition.cursorPosition = @adapter.getCursor()
@localStorage("doc.position.#{@doc_id}", docPosition) @localStorage("doc.position.#{@doc_id}", docPosition)
emitCursorUpdateEvent: () -> emitCursorUpdateEvent: () ->