Merge pull request #14895 from atom/as-fix-block-decoration-measurements

Fix measuring block decorations if adding them before attaching element
This commit is contained in:
Antonio Scandurra
2017-06-27 11:33:58 +02:00
committed by GitHub
2 changed files with 31 additions and 0 deletions

View File

@@ -2035,6 +2035,31 @@ describe('TextEditorComponent', () => {
expect(item6.previousSibling).toBe(lineNodeForScreenRow(component, 12))
})
it('measures block decorations correctly when they are added before the component width has been updated', async () => {
{
const {editor, component, element} = buildComponent({autoHeight: false, width: 500, attach: false})
const marker = editor.markScreenPosition([0, 0])
const item = document.createElement('div')
item.textContent = 'block decoration'
const decoration = editor.decorateMarker(marker, {type: 'block', item})
jasmine.attachToDOM(element)
assertLinesAreAlignedWithLineNumbers(component)
}
{
const {editor, component, element} = buildComponent({autoHeight: false, width: 800})
const marker = editor.markScreenPosition([0, 0])
const item = document.createElement('div')
item.textContent = 'block decoration that could wrap many times'
const decoration = editor.decorateMarker(marker, {type: 'block', item})
element.style.width = '50px'
await component.getNextUpdatePromise()
assertLinesAreAlignedWithLineNumbers(component)
}
})
it('bases the width of the block decoration measurement area on the editor scroll width', async () => {
const {component, element} = buildComponent({autoHeight: false, width: 150})
expect(component.refs.blockDecorationMeasurementArea.offsetWidth).toBe(component.getScrollWidth())

View File

@@ -312,6 +312,11 @@ class TextEditorComponent {
}
})
if (this.resizeBlockDecorationMeasurementsArea) {
this.resizeBlockDecorationMeasurementsArea = false
this.refs.blockDecorationMeasurementArea.style.width = this.getScrollWidth() + 'px'
}
this.blockDecorationsToMeasure.forEach((decoration) => {
const {item} = decoration.getProperties()
const decorationElement = TextEditor.viewForItem(item)
@@ -1391,6 +1396,7 @@ class TextEditorComponent {
if (!this.hasInitialMeasurements) this.measureDimensions()
this.visible = true
this.props.model.setVisible(true)
this.resizeBlockDecorationMeasurementsArea = true
this.updateSync()
this.flushPendingLogicalScrollPosition()
}