Merge pull request #6563 from atom/ns-fix-scroll-width-with-folds

Fix scroll width calculation when longest line is folded
This commit is contained in:
Max Brunsfeld 2015-04-30 14:26:34 -07:00
commit 570c424eae
3 changed files with 17 additions and 5 deletions

View File

@ -499,6 +499,11 @@ describe "TextEditorPresenter", ->
expect(presenter.getState().content.scrollWidth).toBe 10 * editor.getMaxScreenLineLength() + 1
it "isn't clipped to 0 when the longest line is folded (regression)", ->
presenter = buildPresenter(contentFrameWidth: 50, baseCharacterWidth: 10)
editor.foldBufferRow(0)
expect(presenter.getState().content.scrollWidth).toBe 10 * editor.getMaxScreenLineLength() + 1
describe ".scrollTop", ->
it "tracks the value of ::scrollTop", ->
presenter = buildPresenter(scrollTop: 10, lineHeight: 10, explicitHeight: 20)

View File

@ -349,15 +349,15 @@ class TextEditorComponent
if Math.abs(wheelDeltaX) > Math.abs(wheelDeltaY)
# Scrolling horizontally
previousScrollLeft = @editor.getScrollLeft()
previousScrollLeft = @presenter.getScrollLeft()
@presenter.setScrollLeft(previousScrollLeft - Math.round(wheelDeltaX * @scrollSensitivity))
event.preventDefault() unless previousScrollLeft is @editor.getScrollLeft()
event.preventDefault() unless previousScrollLeft is @presenter.getScrollLeft()
else
# Scrolling vertically
@presenter.setMouseWheelScreenRow(@screenRowForNode(event.target))
previousScrollTop = @presenter.scrollTop
previousScrollTop = @presenter.getScrollTop()
@presenter.setScrollTop(previousScrollTop - Math.round(wheelDeltaY * @scrollSensitivity))
event.preventDefault() unless previousScrollTop is @editor.getScrollTop()
event.preventDefault() unless previousScrollTop is @presenter.getScrollTop()
onScrollViewScroll: =>
if @mounted

View File

@ -541,7 +541,8 @@ class TextEditorPresenter
if @baseCharacterWidth?
oldContentWidth = @contentWidth
@contentWidth = @pixelPositionForScreenPosition([@model.getLongestScreenRow(), Infinity]).left
clip = @model.tokenizedLineForScreenRow(@model.getLongestScreenRow())?.isSoftWrapped()
@contentWidth = @pixelPositionForScreenPosition([@model.getLongestScreenRow(), @model.getMaxScreenLineLength()], clip).left
@contentWidth += 1 unless @model.isSoftWrapped() # account for cursor width
if @contentHeight isnt oldContentHeight
@ -691,6 +692,9 @@ class TextEditorPresenter
@updateCustomGutterDecorationState()
@updateOverlaysState()
getScrollTop: ->
@scrollTop
didStartScrolling: ->
if @stoppedScrollingTimeoutId?
clearTimeout(@stoppedScrollingTimeoutId)
@ -720,6 +724,9 @@ class TextEditorPresenter
@updateCursorsState() unless oldScrollLeft?
@updateOverlaysState()
getScrollLeft: ->
@scrollLeft
setHorizontalScrollbarHeight: (horizontalScrollbarHeight) ->
unless @measuredHorizontalScrollbarHeight is horizontalScrollbarHeight
oldHorizontalScrollbarHeight = @measuredHorizontalScrollbarHeight