From 7bcf54a640871792dbd231f992df9acb614adc25 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sun, 12 Nov 2023 17:07:55 -0800 Subject: [PATCH] =?UTF-8?q?Prevent=20=E2=80=9Chalf=20screen=E2=80=9D=20bug?= =?UTF-8?q?=20by=20resetting=20scroll=20position=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …when an editor regains focus. This used to happen until the change in . But we still need this code, presumably because of built-in browser behavior that _implicitly_ scrolls the editor's container to try to move the hidden input back into view. --- src/text-editor-component.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index a60676aad2..4dfd4878da 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1689,6 +1689,13 @@ module.exports = class TextEditorComponent { } didFocusHiddenInput() { + // Focusing the hidden input when it is off-screen causes the browser to + // scroll it into view. Since we use synthetic scrolling this behavior + // causes all the lines to disappear so we counteract it by always setting + // the scroll position to 0. + this.refs.scrollContainer.scrollTop = 0; + this.refs.scrollContainer.scrollLeft = 0; + if (!this.focused) { this.focused = true; this.startCursorBlinking();