Save scroll positions in the model to serialize 'em

This commit is contained in:
Antonio Scandurra
2015-09-23 14:49:11 +02:00
parent 140624326a
commit fffcfb3405
3 changed files with 14 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ TextBuffer = require 'text-buffer'
TextEditor = require '../src/text-editor'
TextEditorPresenter = require '../src/text-editor-presenter'
fdescribe "TextEditorPresenter", ->
describe "TextEditorPresenter", ->
# These `describe` and `it` blocks mirror the structure of the ::state object.
# Please maintain this structure when adding specs for new state fields.
describe "::getState()", ->

View File

@@ -98,8 +98,6 @@ class DisplayBuffer extends Model
copy: ->
newDisplayBuffer = new DisplayBuffer({@buffer, tabLength: @getTabLength(), @largeFileMode})
newDisplayBuffer.setScrollTop(@getScrollTop())
newDisplayBuffer.setScrollLeft(@getScrollLeft())
for marker in @findMarkers(displayBufferId: @id)
marker.copy(displayBufferId: newDisplayBuffer.id)
@@ -1178,6 +1176,17 @@ class DisplayBuffer extends Model
@emit 'marker-created', marker if Grim.includeDeprecatedAPIs
@emitter.emit 'did-create-marker', marker
# TODO: serialize state in TextEditorElement, rather than saving scroll
# positions here.
getScrollTop: -> @scrollTop
setScrollTop: (@scrollTop) ->
getScrollLeft: -> @scrollLeft
setScrollLeft: (@scrollLeft) ->
decorateFold: (fold) ->
@decorateMarker(fold.marker, type: 'line-number', class: 'folded')

View File

@@ -1533,11 +1533,13 @@ class TextEditorPresenter
scrollLeft = Math.round(@constrainScrollLeft(@pendingScrollLeft))
if scrollLeft isnt @scrollLeft and not Number.isNaN(scrollLeft)
@scrollLeft = scrollLeft
@model.setScrollLeft(@scrollLeft)
commitPendingScrollTopPosition: ->
scrollTop = Math.round(@constrainScrollTop(@pendingScrollTop))
if scrollTop isnt @scrollTop and not Number.isNaN(scrollTop)
@scrollTop = scrollTop
@model.setScrollTop(@scrollTop)
updateScrollPosition: ->
@commitPendingLogicalScrollPosition() if @pendingScrollLogicalPosition?