]> cat aescling's git repositories - mastodon.git/commitdiff
Only scroll to the compose form if it's not horizontally in the viewport (#11246)
authorThibG <thib@sitedethib.com>
Sat, 6 Jul 2019 16:18:08 +0000 (18:18 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Sat, 6 Jul 2019 16:18:08 +0000 (18:18 +0200)
Avoids jumping the scroll around vertically when giving it focus and
editing long toots.

app/javascript/mastodon/features/compose/components/compose_form.js

index 1f476397faa67f4d196e75ed59933b7db6049dee..47e189251c9f0d1ab8babe42b69576002db3bfc1 100644 (file)
@@ -117,7 +117,10 @@ class ComposeForm extends ImmutablePureComponent {
 
   handleFocus = () => {
     if (this.composeForm && !this.props.singleColumn) {
-      this.composeForm.scrollIntoView();
+      const { left, right } = this.composeForm.getBoundingClientRect();
+      if (left < 0 || right > (window.innerWidth || document.documentElement.clientWidth)) {
+        this.composeForm.scrollIntoView();
+      }
     }
   }