Merge pull request #15338 from atom/ns-hide-extra-lines-to-measure

Hide off-screen lines when we render them for measurement
This commit is contained in:
Nathan Sobo
2017-08-16 10:45:29 -06:00
committed by GitHub
2 changed files with 23 additions and 1 deletions

View File

@@ -3765,6 +3765,22 @@ describe('TextEditorComponent', () => {
component.screenPositionForPixelPosition({top: 800, left: 1})
await updatePromise
})
it('does not shift cursors downward or render off-screen content when measuring off-screen lines (regression)', async () => {
const {component, element, editor} = buildComponent({rowsPerTile: 2, autoHeight: false})
await setEditorHeightInLines(component, 3)
const {top, left} = component.pixelPositionForScreenPosition({row: 12, column: 1})
expect(element.querySelector('.cursor').getBoundingClientRect().top).toBe(component.refs.lineTiles.getBoundingClientRect().top)
expect(element.querySelector('.line[data-screen-row="12"]').style.visibility).toBe('hidden')
// Ensure previously measured off screen lines don't have any weird
// styling when they come on screen in the next frame
await setEditorHeightInLines(component, 13)
const previouslyMeasuredLineElement = element.querySelector('.line[data-screen-row="12"]')
expect(previouslyMeasuredLineElement.style.display).toBe('')
expect(previouslyMeasuredLineElement.style.visibility).toBe('')
})
})
describe('screenPositionForPixelPosition', () => {

View File

@@ -618,6 +618,7 @@ class TextEditorComponent {
if (screenRow < startRow || screenRow >= endRow) {
children.push($(LineComponent, {
key: 'extra-' + screenLine.id,
hidden: true,
screenLine,
screenRow,
displayLayer: this.props.model.displayLayer,
@@ -3863,11 +3864,16 @@ class LineComponent {
}
appendContents () {
const {displayLayer, nodePool, screenLine, textDecorations, textNodesByScreenLineId} = this.props
const {displayLayer, nodePool, hidden, screenLine, textDecorations, textNodesByScreenLineId} = this.props
const textNodes = []
textNodesByScreenLineId.set(screenLine.id, textNodes)
if (hidden) {
this.element.style.position = 'absolute'
this.element.style.visibility = 'hidden'
}
const {lineText, tags} = screenLine
let openScopeNode = nodePool.getElement('SPAN', null, null)
this.element.appendChild(openScopeNode)