|
|
@@ -3,47 +3,49 @@ define [], () ->
|
|
|
constructor: (@$scope, @editor, @element) ->
|
|
|
|
|
|
@editor.on "changeSession", (e) =>
|
|
|
- e.session.on "changeScrollTop", (e) =>
|
|
|
- @onScrollTopChange(e)
|
|
|
+ if e.oldSession?
|
|
|
+ @storeCursorPosition(e.oldSession)
|
|
|
+ @storeScrollTopPosition(e.oldSession)
|
|
|
+
|
|
|
+ @doc_id = @$scope.sharejsDoc?.doc_id
|
|
|
|
|
|
e.session.selection.on 'changeCursor', (e) =>
|
|
|
- @onCursorChange(e)
|
|
|
+ @emitCursorUpdateEvent(e)
|
|
|
+
|
|
|
+ setTimeout () =>
|
|
|
+ @gotoStoredPosition()
|
|
|
+ , 0
|
|
|
|
|
|
- @gotoStoredPosition()
|
|
|
+ $(window).on "unload", () =>
|
|
|
+ @storeCursorPosition(@editor.getSession())
|
|
|
+ @storeScrollTopPosition(@editor.getSession())
|
|
|
|
|
|
- @$scope.$watch "gotoLine", (value) =>
|
|
|
+ @$scope.$on "#{@$scope.name}:gotoLine", (editor, value) =>
|
|
|
console.log "Going to line", value
|
|
|
if value?
|
|
|
setTimeout () =>
|
|
|
@gotoLine(value)
|
|
|
- @$scope.$apply () =>
|
|
|
- @$scope.gotoLine = null
|
|
|
, 0
|
|
|
|
|
|
- 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)
|
|
|
+ storeScrollTopPosition: (session) ->
|
|
|
+ if @doc_id?
|
|
|
+ docPosition = $.localStorage("doc.position.#{@doc_id}") || {}
|
|
|
+ docPosition.scrollTop = session.getScrollTop()
|
|
|
+ $.localStorage("doc.position.#{@doc_id}", docPosition)
|
|
|
+
|
|
|
+ storeCursorPosition: (session) ->
|
|
|
+ if @doc_id?
|
|
|
+ docPosition = $.localStorage("doc.position.#{@doc_id}") || {}
|
|
|
+ docPosition.cursorPosition = session.selection.getCursor()
|
|
|
+ $.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?
|
|
|
- pos = $.localStorage("doc.position.#{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)
|