mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Save scroll positions in the model to serialize 'em
This commit is contained in:
@@ -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()", ->
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user