From 9cf7f609f5141be3353e5796d3820eb36d09329a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 16 Aug 2017 15:22:46 -0600 Subject: [PATCH] Round return values of getMaxScrollTop/Left --- spec/text-editor-component-spec.js | 17 +++++++++++++++++ src/text-editor-component.js | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 0d0be1949..252f0b739 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -205,6 +205,23 @@ describe('TextEditorComponent', () => { expect(component.getFirstVisibleRow()).toBe(editor.getScreenLineCount() + 1) }) + it('does not fire onDidChangeScrollTop listeners when assigning the same maximal value and the content height has fractional pixels (regression)', async () => { + const {component, element, editor} = buildComponent({autoHeight: false, autoWidth: false}) + await setEditorHeightInLines(component, 3) + + // Force a fractional content height with a block decoration + const item = document.createElement("div") + item.style.height = '10.6px' + editor.decorateMarker(editor.markBufferPosition([0, 0]), {type: "block", item}) + await component.getNextUpdatePromise() + + component.setScrollTop(Infinity) + element.onDidChangeScrollTop((newScrollTop) => { + throw new Error('Scroll top should not have changed') + }) + component.setScrollTop(component.getScrollTop()) + }) + it('gives the line number tiles an explicit width and height so their layout can be strictly contained', async () => { const {component, element, editor} = buildComponent({rowsPerTile: 3}) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index b38f34cc5..fdb766454 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -2728,7 +2728,7 @@ class TextEditorComponent { } getMaxScrollTop () { - return Math.max(0, this.getScrollHeight() - this.getScrollContainerClientHeight()) + return Math.round(Math.max(0, this.getScrollHeight() - this.getScrollContainerClientHeight())) } getScrollBottom () { @@ -2756,7 +2756,7 @@ class TextEditorComponent { } getMaxScrollLeft () { - return Math.max(0, this.getScrollWidth() - this.getScrollContainerClientWidth()) + return Math.round(Math.max(0, this.getScrollWidth() - this.getScrollContainerClientWidth())) } getScrollRight () {