Store first visible line instead of scrollTop

scrollTop is affected by changing viewport size and switching between
Ace and CM
This commit is contained in:
Alasdair Smith 2018-07-05 17:24:45 +01:00
parent 6c7e942470
commit ba9fa9a0be
2 changed files with 10 additions and 13 deletions

View file

@ -7,19 +7,16 @@ define [
getCursor: () ->
@editor.getCursorPosition()
getCursorForSession: (session) ->
session.selection.getCursor()
getScrollTopForSession: (session) ->
session.getScrollTop()
getEditorScrollPosition: () ->
@editor.getFirstVisibleRow()
setCursor: (pos) ->
pos = pos.cursorPosition or { row: 0, column: 0 }
@editor.moveCursorToPosition(pos)
setScrollTop: (pos) ->
pos = pos.scrollTop or 0
@editor.getSession().setScrollTop(pos)
setEditorScrollPosition: (pos) ->
pos = pos.firstVisibleLine or 0
@editor.scrollToLine(pos)
clearSelection: () ->
@editor.selection.clearSelection()

View file

@ -22,7 +22,7 @@ define [], () ->
onSessionChange: (e) =>
if e.oldSession?
@storeCursorPosition(e.oldSession)
@storeScrollTopPosition(e.oldSession)
@storeFirstVisibleLine()
@doc_id = @$scope.sharejsDoc?.doc_id
@ -32,15 +32,15 @@ define [], () ->
onUnload: (session) =>
@storeCursorPosition(session)
@storeScrollTopPosition(session)
@storeFirstVisibleLine()
onCursorChange: () =>
@emitCursorUpdateEvent()
storeScrollTopPosition: (session) ->
storeFirstVisibleLine: () ->
if @doc_id?
docPosition = @localStorage("doc.position.#{@doc_id}") || {}
docPosition.scrollTop = @adapter.getScrollTopForSession(session)
docPosition.firstVisibleLine = @adapter.getEditorScrollPosition()
@localStorage("doc.position.#{@doc_id}", docPosition)
storeCursorPosition: (session) ->
@ -57,4 +57,4 @@ define [], () ->
return if !@doc_id?
pos = @localStorage("doc.position.#{@doc_id}") || {}
@adapter.setCursor(pos)
@adapter.setScrollTop(pos)
@adapter.setEditorScrollPosition(pos)