ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.63k stars 3.71k forks source link

Editor content scrolls to the top after switching browser tabs when a dropdown menu is opened #16274

Open mabryl opened 7 months ago

mabryl commented 7 months ago

📝 Provide detailed reproduction steps (if any)

  1. Open an editor that has a dropdown menu on the toolbar, e.g. Heading
  2. Select some content in the editor that's towards the bottom of the editable
  3. Click on the dropdown on the toolbar
  4. With the dropdown open, switch to a different tab in the browser
  5. Switch back to the tab with the editor

✔️ Expected result

The editor should be focused back where the selection was, as is the case when no dropdown is open:

https://github.com/ckeditor/ckeditor5/assets/72079603/be619139-6161-40e8-9971-53f35d6a03a5

❌ Actual result

The editor will scroll up to the top of the editable, even though the text is still selected:

https://github.com/ckeditor/ckeditor5/assets/72079603/0d20a5cd-2b8c-4285-b559-bce5ba6e5d8e

📃 Other details


If you'd like to see this fixed sooner, add a 👍 reaction to this post.

Mati365 commented 2 months ago

Introduced here https://github.com/ckeditor/ckeditor5/pull/17013 , this region is causing issue:

https://github.com/ckeditor/ckeditor5/blob/ck/17067/packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.ts#L463-L472

        // Watch scroll event only when the button is visible, it prevents attaching the scroll event listener
        // to the document when the button is not visible.
        buttonView.on<ObservableChangeEvent<boolean>>( 'change:isVisible', ( evt, name, isVisible ) => {
            if ( isVisible ) {
                buttonView.listenTo( global.document, 'scroll', repositionOnScroll, {
                    useCapture: true,
                    usePassive: true
                } );
            } else {
                buttonView.stopListening( global.document, 'scroll', repositionOnScroll );
            }
        } );