Skip to content

Fake selection is not updated on editor content change #18123

@niegowski

Description

@niegowski

📝 Provide detailed reproduction steps (if any)

  1. Add a button to the manual test after an editor with the following handler attached:
document.querySelector( '#save' ).addEventListener( 'click', e => {
	e.preventDefault();

	editor.enableReadOnlyMode( 'saving' );
	editor.setData( '' );

	window.document.dispatchEvent( new window.Event( 'selectionchange' ) );

	editor.disableReadOnlyMode( 'saving' );
	editor.focus();
} );
  1. In the editor select an image
  2. Click created button

✔️ Expected result

Editor content is cleared and editor does not crash.

❌ Actual result

Editor crashes with the _handleSelectionChange in the stack trace.

❓ Possible solution

While debugging I noticed that the fake selection container <-> view selection map is not verified if the selection is still valid and tries to convert an invalid cached selection to model:

const viewSelection = this.fakeSelectionToView( container as DomElement );

📃 Other details

  • Browser: …
  • OS: …
  • First affected CKEditor version: …
  • Installed CKEditor plugins: …

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    support:2An issue reported by a commercially licensed client.type:bugThis issue reports a buggy (incorrect) behavior.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions