From e6e5420f425bba269b18a923b2c88825689b7bbb Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Mar 2017 10:24:27 -0600 Subject: [PATCH] Correctly handle overflows caused by scrollbar for the opposite axis --- spec/text-editor-component-spec.js | 25 +++++++++++++++++++++++++ src/text-editor-component.js | 22 ++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 841008b37..b1e1a8a25 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -163,6 +163,31 @@ describe('TextEditorComponent', () => { expect(getVerticalScrollbarWidth(component)).toBe(0) expect(getHorizontalScrollbarHeight(component)).toBe(0) expect(component.refs.scrollbarCorner).toBeUndefined() + + editor.setText(SAMPLE_TEXT) + await component.getNextUpdatePromise() + + // Does not show scrollbars if the content perfectly fits + element.style.width = component.getGutterContainerWidth() + component.getContentWidth() + 'px' + element.style.height = component.getContentHeight() + 'px' + await component.getNextUpdatePromise() + expect(getVerticalScrollbarWidth(component)).toBe(0) + expect(getHorizontalScrollbarHeight(component)).toBe(0) + + // Shows scrollbars if the only reason we overflow is the presence of the + // scrollbar for the opposite axis. + element.style.width = component.getGutterContainerWidth() + component.getContentWidth() - 1 + 'px' + element.style.height = component.getContentHeight() + component.getHorizontalScrollbarHeight() - 1 + 'px' + await component.getNextUpdatePromise() + expect(getVerticalScrollbarWidth(component)).toBeGreaterThan(0) + expect(getHorizontalScrollbarHeight(component)).toBeGreaterThan(0) + + element.style.width = component.getGutterContainerWidth() + component.getContentWidth() + component.getVerticalScrollbarWidth() - 1 + 'px' + element.style.height = component.getContentHeight() - 1 + 'px' + await component.getNextUpdatePromise() + expect(getVerticalScrollbarWidth(component)).toBeGreaterThan(0) + expect(getHorizontalScrollbarHeight(component)).toBeGreaterThan(0) + }) it('updates the bottom/right of dummy scrollbars and client height/width measurements when scrollbar styles change', async () => { diff --git a/src/text-editor-component.js b/src/text-editor-component.js index dc3f7dd66..b89027d3c 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1581,7 +1581,10 @@ class TextEditorComponent { isVerticalScrollbarVisible () { return ( this.getContentHeight() > this.getScrollContainerHeight() || - this.isContentMinimallyOverlappingBothScrollbars() + ( + this.getContentWidth() > this.getScrollContainerWidth() && + this.getContentHeight() > (this.getScrollContainerHeight() - this.getHorizontalScrollbarHeight()) + ) ) } @@ -1590,23 +1593,14 @@ class TextEditorComponent { !this.props.model.isSoftWrapped() && ( this.getContentWidth() > this.getScrollContainerWidth() || - this.isContentMinimallyOverlappingBothScrollbars() + ( + this.getContentHeight() > this.getScrollContainerHeight() && + this.getContentWidth() > (this.getScrollContainerWidth() - this.getVerticalScrollbarWidth()) + ) ) ) } - isContentMinimallyOverlappingBothScrollbars () { - const clientHeightWithHorizontalScrollbar = - this.getScrollContainerHeight() - this.getHorizontalScrollbarHeight() - const clientWidthWithVerticalScrollbar = - this.getScrollContainerWidth() - this.getVerticalScrollbarWidth() - - return ( - this.getContentHeight() > clientHeightWithHorizontalScrollbar && - this.getContentWidth() > clientWidthWithVerticalScrollbar - ) - } - getScrollHeight () { if (this.props.model.getScrollPastEnd()) { return this.getContentHeight() + Math.max(