mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Schedule update when setting scroll top row or scroll left column
This commit is contained in:
@@ -2837,28 +2837,40 @@ describe('TextEditorComponent', () => {
|
||||
await component.getNextUpdatePromise()
|
||||
|
||||
expect(component.getMaxScrollTop() / component.getLineHeight()).toBe(9)
|
||||
expect(component.refs.verticalScrollbar.element.scrollTop).toBe(0 * component.getLineHeight())
|
||||
|
||||
editor.setFirstVisibleScreenRow(1)
|
||||
expect(component.getFirstVisibleRow()).toBe(1)
|
||||
await component.getNextUpdatePromise()
|
||||
expect(component.refs.verticalScrollbar.element.scrollTop).toBe(1 * component.getLineHeight())
|
||||
|
||||
editor.setFirstVisibleScreenRow(5)
|
||||
expect(component.getFirstVisibleRow()).toBe(5)
|
||||
await component.getNextUpdatePromise()
|
||||
expect(component.refs.verticalScrollbar.element.scrollTop).toBe(5 * component.getLineHeight())
|
||||
|
||||
editor.setFirstVisibleScreenRow(11)
|
||||
expect(component.getFirstVisibleRow()).toBe(9)
|
||||
await component.getNextUpdatePromise()
|
||||
expect(component.refs.verticalScrollbar.element.scrollTop).toBe(9 * component.getLineHeight())
|
||||
})
|
||||
|
||||
it('delegates setFirstVisibleScreenColumn and getFirstVisibleScreenColumn to the component', async () => {
|
||||
const {component, element, editor} = buildComponent({rowsPerTile: 3, autoHeight: false})
|
||||
element.style.width = 30 * component.getBaseCharacterWidth() + 'px'
|
||||
await component.getNextUpdatePromise()
|
||||
|
||||
expect(editor.getFirstVisibleScreenColumn()).toBe(0)
|
||||
component.setScrollLeft(5.5 * component.getBaseCharacterWidth())
|
||||
expect(component.refs.horizontalScrollbar.element.scrollLeft).toBe(0 * component.getBaseCharacterWidth())
|
||||
|
||||
setScrollLeft(component, 5.5 * component.getBaseCharacterWidth())
|
||||
expect(editor.getFirstVisibleScreenColumn()).toBe(5)
|
||||
await component.getNextUpdatePromise()
|
||||
expect(component.refs.horizontalScrollbar.element.scrollLeft).toBe(Math.round(5.5 * component.getBaseCharacterWidth()))
|
||||
|
||||
editor.setFirstVisibleScreenColumn(12)
|
||||
expect(component.getScrollLeft()).toBe(Math.round(12 * component.getBaseCharacterWidth()))
|
||||
await component.getNextUpdatePromise()
|
||||
expect(component.refs.horizontalScrollbar.element.scrollLeft).toBe(Math.round(12 * component.getBaseCharacterWidth()))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1728,13 +1728,13 @@ class TextEditorComponent {
|
||||
flushPendingLogicalScrollPosition () {
|
||||
let changedScrollTop = false
|
||||
if (this.pendingScrollTopRow > 0) {
|
||||
changedScrollTop = this.setScrollTopRow(this.pendingScrollTopRow)
|
||||
changedScrollTop = this.setScrollTopRow(this.pendingScrollTopRow, false)
|
||||
this.pendingScrollTopRow = null
|
||||
}
|
||||
|
||||
let changedScrollLeft = false
|
||||
if (this.pendingScrollLeftColumn > 0) {
|
||||
changedScrollLeft = this.setScrollLeftColumn(this.pendingScrollLeftColumn)
|
||||
changedScrollLeft = this.setScrollLeftColumn(this.pendingScrollLeftColumn, false)
|
||||
this.pendingScrollLeftColumn = null
|
||||
}
|
||||
|
||||
@@ -2466,13 +2466,17 @@ class TextEditorComponent {
|
||||
return this.setScrollLeft(scrollRight - this.getScrollContainerClientWidth())
|
||||
}
|
||||
|
||||
setScrollTopRow (scrollTopRow) {
|
||||
setScrollTopRow (scrollTopRow, scheduleUpdate = true) {
|
||||
if (this.measurements) {
|
||||
return this.setScrollTop(this.pixelPositionBeforeBlocksForRow(scrollTopRow))
|
||||
const didScroll = this.setScrollTop(this.pixelPositionBeforeBlocksForRow(scrollTopRow))
|
||||
if (didScroll && scheduleUpdate) {
|
||||
this.scheduleUpdate()
|
||||
}
|
||||
return didScroll
|
||||
} else {
|
||||
this.pendingScrollTopRow = scrollTopRow
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
getScrollTopRow () {
|
||||
@@ -2483,13 +2487,17 @@ class TextEditorComponent {
|
||||
}
|
||||
}
|
||||
|
||||
setScrollLeftColumn (scrollLeftColumn) {
|
||||
setScrollLeftColumn (scrollLeftColumn, scheduleUpdate = true) {
|
||||
if (this.measurements && this.getLongestLineWidth() != null) {
|
||||
return this.setScrollLeft(scrollLeftColumn * this.getBaseCharacterWidth())
|
||||
const didScroll = this.setScrollLeft(scrollLeftColumn * this.getBaseCharacterWidth())
|
||||
if (didScroll && scheduleUpdate) {
|
||||
this.scheduleUpdate()
|
||||
}
|
||||
return didScroll
|
||||
} else {
|
||||
this.pendingScrollLeftColumn = scrollLeftColumn
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
getScrollLeftColumn () {
|
||||
|
||||
Reference in New Issue
Block a user