From a1b61e77ff81ce2e72aa3f3dc925b749d760dee6 Mon Sep 17 00:00:00 2001 From: Ben Klein Date: Wed, 22 Jan 2020 21:21:51 -0500 Subject: [PATCH] If Text Editor Component uses the scroll event, consume it / prevent bubbling In a normal browser the inner scrollable would scroll to the edge before then scrolling the parent. This change makes it consistent with expected HTML scroll behaviour. Without it, the scroll event continues outside the editor to any other element containing it, even though the scroll event already was acted upon by the child (text editor component). If a package wanted to also use the mouse wheel event when integrating into a text editor (or if the text editor itself is inside something scrollable) this change makes more sense as it prevents multiple responses to a single user input. There doesn't appear to be any side effects to this change. (Tested on linux: Pop_OS 19.10, 1.42.0) --- src/text-editor-component.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 04537c038..61379cbfc 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1736,7 +1736,10 @@ module.exports = class TextEditorComponent { const scrollTopChanged = wheelDeltaY !== 0 && this.setScrollTop(this.getScrollTop() - wheelDeltaY); - if (scrollLeftChanged || scrollTopChanged) this.updateSync(); + if (scrollLeftChanged || scrollTopChanged) { + event.preventDefault(); + this.updateSync(); + } } didResize() {