From e2cf60a0c92f6db61cea26b817b7b7a5d51271eb Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 12 Apr 2017 19:07:05 +0200 Subject: [PATCH] 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. --- src/text-editor-component.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 0b5a78d8a..cd8ebcb77 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -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++) {