From de54e558787dc28226c1f40317c529daa0d58abd Mon Sep 17 00:00:00 2001 From: Linus Eriksson Date: Wed, 28 Feb 2018 09:24:18 +0100 Subject: [PATCH] Fix shaking editor when typing When using DPI scaling the scroll position could be set to a position that was not possible causing a scroll event to scroll back. This was causing the editor to shake when editing. This PR fixes this by rounding scrollTop and scrollLeft to a physical pixel instead of rounding using Math.round Co-authored-by: Antonio Scandurra --- src/text-editor-component.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 38851d88d..3e56dd821 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -2811,7 +2811,7 @@ class TextEditorComponent { setScrollTop (scrollTop) { if (Number.isNaN(scrollTop) || scrollTop == null) return false - scrollTop = Math.round(Math.max(0, Math.min(this.getMaxScrollTop(), scrollTop))) + scrollTop = roundToPhysicalPixelBoundary(Math.max(0, Math.min(this.getMaxScrollTop(), scrollTop))) if (scrollTop !== this.scrollTop) { this.derivedDimensionsCache = {} this.scrollTopPending = true @@ -2842,7 +2842,7 @@ class TextEditorComponent { setScrollLeft (scrollLeft) { if (Number.isNaN(scrollLeft) || scrollLeft == null) return false - scrollLeft = Math.round(Math.max(0, Math.min(this.getMaxScrollLeft(), scrollLeft))) + scrollLeft = roundToPhysicalPixelBoundary(Math.max(0, Math.min(this.getMaxScrollLeft(), scrollLeft))) if (scrollLeft !== this.scrollLeft) { this.scrollLeftPending = true this.scrollLeft = scrollLeft