mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Test and fix the center option to autoscroll
This commit is contained in:
committed by
Antonio Scandurra
parent
8652222b22
commit
eb588d4c7c
@@ -523,6 +523,18 @@ describe('TextEditorComponent', () => {
|
||||
expect(component.getScrollBottom()).toBe((6 + 1 + scrollMarginInLines) * component.measurements.lineHeight)
|
||||
})
|
||||
|
||||
it('autoscrolls the given range to the center of the screen if the `center` option is true', async () => {
|
||||
const {component, editor} = buildComponent({height: 50})
|
||||
expect(component.getLastVisibleRow()).toBe(3)
|
||||
|
||||
editor.scrollToScreenRange([[4, 0], [6, 0]], {center: true})
|
||||
await component.getNextUpdatePromise()
|
||||
|
||||
const actualScrollCenter = (component.getScrollTop() + component.getScrollBottom()) / 2
|
||||
const expectedScrollCenter = Math.round((4 + 7) / 2 * component.getLineHeight())
|
||||
expect(actualScrollCenter).toBe(expectedScrollCenter)
|
||||
})
|
||||
|
||||
it('automatically scrolls horizontally when the requested range is within the horizontal scroll margin of the right edge of the gutter or right edge of the scroll container', async () => {
|
||||
const {component, element, editor} = buildComponent()
|
||||
const {scrollContainer} = component.refs
|
||||
|
||||
@@ -1472,8 +1472,8 @@ class TextEditorComponent {
|
||||
if (options && options.center) {
|
||||
const desiredScrollCenter = (screenRangeTop + screenRangeBottom) / 2
|
||||
if (desiredScrollCenter < this.getScrollTop() || desiredScrollCenter > this.getScrollBottom()) {
|
||||
desiredScrollTop = desiredScrollCenter - this.measurements.clientHeight / 2
|
||||
desiredScrollBottom = desiredScrollCenter + this.measurements.clientHeight / 2
|
||||
desiredScrollTop = desiredScrollCenter - this.getScrollContainerClientHeight() / 2
|
||||
desiredScrollBottom = desiredScrollCenter + this.getScrollContainerClientHeight() / 2
|
||||
}
|
||||
} else {
|
||||
desiredScrollTop = screenRangeTop - verticalScrollMargin
|
||||
|
||||
Reference in New Issue
Block a user