mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Test that the logical scroll event is triggered
This commit is contained in:
@@ -1234,31 +1234,17 @@ describe "DisplayBuffer", ->
|
||||
expect(displayBuffer.getDecorations(class: 'one').length).toEqual 1
|
||||
|
||||
describe "::scrollToScreenPosition(position, [options])", ->
|
||||
beforeEach ->
|
||||
displayBuffer.setLineHeightInPixels(10)
|
||||
displayBuffer.setDefaultCharWidth(10)
|
||||
displayBuffer.setHorizontalScrollbarHeight(0)
|
||||
displayBuffer.setHeight(50)
|
||||
displayBuffer.setWidth(150)
|
||||
|
||||
it "sets the scroll top and scroll left so the given screen position is in view", ->
|
||||
displayBuffer.scrollToScreenPosition([8, 20])
|
||||
expect(displayBuffer.getScrollBottom()).toBe (9 + displayBuffer.getVerticalScrollMargin()) * 10
|
||||
expect(displayBuffer.getScrollRight()).toBe (20 + displayBuffer.getHorizontalScrollMargin()) * 10
|
||||
it "triggers ::onDidChangeScrollPosition with the logical coordinates along with the options", ->
|
||||
scrollSpy = jasmine.createSpy("::onDidChangeScrollPosition")
|
||||
displayBuffer.onDidChangeScrollPosition(scrollSpy)
|
||||
|
||||
displayBuffer.scrollToScreenPosition([8, 20])
|
||||
expect(displayBuffer.getScrollBottom()).toBe (9 + displayBuffer.getVerticalScrollMargin()) * 10
|
||||
expect(displayBuffer.getScrollRight()).toBe (20 + displayBuffer.getHorizontalScrollMargin()) * 10
|
||||
displayBuffer.scrollToScreenPosition([8, 20], center: true)
|
||||
displayBuffer.scrollToScreenPosition([8, 20], center: false, reversed: true)
|
||||
|
||||
describe "when the 'center' option is true", ->
|
||||
it "vertically scrolls to center the given position vertically", ->
|
||||
displayBuffer.scrollToScreenPosition([8, 20], center: true)
|
||||
expect(displayBuffer.getScrollTop()).toBe (8 * 10) + 5 - (50 / 2)
|
||||
expect(displayBuffer.getScrollRight()).toBe (20 + displayBuffer.getHorizontalScrollMargin()) * 10
|
||||
|
||||
it "does not scroll vertically if the position is already in view", ->
|
||||
displayBuffer.scrollToScreenPosition([4, 20], center: true)
|
||||
expect(displayBuffer.getScrollTop()).toBe 0
|
||||
expect(scrollSpy).toHaveBeenCalledWith(screenRange: [[8, 20], [8, 20]], options: {})
|
||||
expect(scrollSpy).toHaveBeenCalledWith(screenRange: [[8, 20], [8, 20]], options: {center: true})
|
||||
expect(scrollSpy).toHaveBeenCalledWith(screenRange: [[8, 20], [8, 20]], options: {center: false, reversed: true})
|
||||
|
||||
describe "scroll width", ->
|
||||
cursorWidth = 1
|
||||
|
||||
@@ -362,7 +362,7 @@ class DisplayBuffer extends Model
|
||||
{start, end} = selection.getScreenRange()
|
||||
@intersectsVisibleRowRange(start.row, end.row + 1)
|
||||
|
||||
logicalScrollToScreenRange: (screenRange, options) ->
|
||||
logicalScrollToScreenRange: (screenRange, options = {}) ->
|
||||
scrollEvent = {screenRange, options}
|
||||
@emitter.emit "did-change-scroll-position", scrollEvent
|
||||
|
||||
@@ -389,14 +389,6 @@ class DisplayBuffer extends Model
|
||||
desiredScrollLeft = left - horizontalScrollMarginInPixels
|
||||
desiredScrollRight = right + horizontalScrollMarginInPixels
|
||||
|
||||
if global.enableLogs
|
||||
console.log "====== DB ======"
|
||||
console.log "Screen Range: #{screenRange.toString()}"
|
||||
console.log "Client Width: #{@getClientWidth()}"
|
||||
console.log "#{desiredScrollLeft}/#{desiredScrollRight}"
|
||||
console.log "#{@getScrollLeft()}/#{@getScrollRight()}"
|
||||
console.log "================"
|
||||
|
||||
if options?.reversed ? true
|
||||
if desiredScrollBottom > @getScrollBottom()
|
||||
@setScrollBottom(desiredScrollBottom)
|
||||
|
||||
Reference in New Issue
Block a user