question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Body jumping to the top when you refocus (after losing focus)

See original GitHub issue

Steps for Reproduction

  1. Visit lesson 10 of cloning medium guide.
  2. Press enter a bunch of time and then scroll down so that top of the screen is out of the viewport. (Basically, till you can’t see “tell your story…”)
  3. Click anywhere outside the editor area so that editor loses focus.
  4. Now click on the sidebar button directly and you can see the document jumping at the top even though it sets the cursor at the correct position.

Expected behavior: Expect body ( scroll container ) to not jump at the top and set the cursor at the position it was before.

Actual behavior: Body( scroll container ) jumps at the top but sets the cursor position at the correct range.

Platforms: Browser: Chrome, Version 66.0.3359.139 (Official Build) (64-bit) OS: MacOS El Capitan, 10.11.6

Version:

Quill version: 1.3.6

I think i have narrowed down the issue to this part of the code

 restoreFocus() {
    let scrollTop = this.quill.scrollingContainer.scrollTop;
    this.quill.focus();
    this.quill.scrollingContainer.scrollTop = scrollTop;
  }

This behaviour is also reproducible when you use setSelection(index) method.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:11
  • Comments:5

github_iconTop GitHub Comments

1reaction
notngancommented, Sep 13, 2019

This happened to me too when I insert a link into toolbar and press Enter. After debugging I think it’s caused by this line

if (!this.hasFocus()) this.root.focus();

Here is my temporary solution that helps scrolling into the previous selection.

const selectionEl = window.getSelection().focusNode.parentElement
selectionEl.scrollIntoView({ block: 'center', inline: 'center' })

See more scroll options.

Theme: Bubble

Browsers: Chrome/76.0.3809.132 Safari/537.36

0reactions
doanhtu07commented, May 19, 2021
    // Prevent the editor to jump to the top when refocusing

    this.mQuillEditor?.root.addEventListener("blur", () => {
      if (this.mQuillEditor) {
        this.mBodyTop = document.body.getBoundingClientRect().top;
      }
    });

    this.mQuillEditor?.root.addEventListener("focus", () => {
      if (this.mBodyTop === null) {
        return;
      }
      window.scrollTo({
        top: Math.abs(this.mBodyTop)
      });
    });

Notes: this.mQuillEditor = new Quill(ref, options); this.mBodyTop is just a storing variable.

I find the solution here: https://github.com/quilljs/quill/issues/855 But I change it up a little so it actually works. At least, it works for me.

Versions: Quill ^1.3.7 Theme snow Chrome Version 90.0.4430.212

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why You Can't Focus And How to Stop Losing Focus - Lifehack
Being overburdened can increase stress and anxiety which we already identified as causes for lack of focus.
Read more >
3 Ways to Refocus Your Attention on Fitness
Losing motivation and focus definitely happens. And most of the time, it's truly not the end of the world. But if you're ready...
Read more >
React.js - input losing focus when rerendering - Stack Overflow
The reason input was losing focus in my case was due to the fact that I was re-rendering the input on state change....
Read more >
Need Help Staying Focused? Try These 10 Tips - Healthline
Learn proven ways to improve your focus and concentration at work, school, ... You may also find that the following behavioral practices may...
Read more >
7 Steps to Regaining Your Focus - Entrepreneur
1) Remind yourself why you're in business. · 2) List your top priorities. · 3) Synchronize your breath and body. · 4) Drink...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found