Don't reuse resize detectors across TextEditorComponent instances

Due to the way element-resize-detector schedules the delivering of
resize events, this will ensure that creating an editor while the clock
is mocked won't prevent subsequent tests using the real clock from
getting such events.
This commit is contained in:
Antonio Scandurra
2017-04-12 19:07:05 +02:00
parent b7a421eadf
commit e2cf60a0c9

View File

@@ -138,9 +138,10 @@ class TextEditorComponent {
etch.updateSync(this)
this.observeModel()
getElementResizeDetector().listenTo(this.element, this.didResize.bind(this))
this.resizeDetector = ResizeDetector({strategy: 'scroll'})
this.resizeDetector.listenTo(this.element, this.didResize.bind(this))
if (this.refs.gutterContainer) {
getElementResizeDetector().listenTo(this.refs.gutterContainer, this.didResizeGutterContainer.bind(this))
this.resizeDetector.listenTo(this.refs.gutterContainer, this.didResizeGutterContainer.bind(this))
}
}
@@ -759,7 +760,7 @@ class TextEditorComponent {
renderOverlayDecorations () {
return this.decorationsToRender.overlays.map((overlayProps) =>
$(OverlayComponent, Object.assign(
{key: overlayProps.element, didResize: this.updateSync},
{key: overlayProps.element, resizeDetector: this.resizeDetector, didResize: this.updateSync},
overlayProps
))
)
@@ -3178,7 +3179,7 @@ class OverlayComponent {
this.element.style.zIndex = 4
this.element.style.top = (this.props.pixelTop || 0) + 'px'
this.element.style.left = (this.props.pixelLeft || 0) + 'px'
getElementResizeDetector().listenTo(this.element, this.props.didResize)
this.props.resizeDetector.listenTo(this.element, this.props.didResize)
}
update (newProps) {
@@ -3211,12 +3212,6 @@ function clientRectForRange (textNode, startIndex, endIndex) {
return rangeForMeasurement.getBoundingClientRect()
}
let resizeDetector
function getElementResizeDetector () {
if (resizeDetector == null) resizeDetector = ResizeDetector({strategy: 'scroll'})
return resizeDetector
}
function arraysEqual (a, b) {
if (a.length !== b.length) return false
for (let i = 0, length = a.length; i < length; i++) {