Skip to content

Cursor position is lost after adding media in WYSIWYG editor #16847

@amiralitaheri

Description

@amiralitaheri

Bug report

Required System information

  • Node.js version: 18
  • NPM version: 8.19.2
  • Strapi version: 4.10.6
  • Is your project Javascript or Typescript: Javascript

Describe the bug

After inserting an image into editor, The cursor will jump to start of the editor.

Steps to reproduce the behavior

  1. Go to a component that has rich text editor
  2. Write a lorem document
  3. Go to the bottom of document
  4. Click on insert image from editor navbar
  5. Cursor will jump to the start!

Expected behavior

Text cursor should be on the beginning or the end of the line that image was inserted or the next line.

Additional context


The focus should be followed by a setCursor like in here:
setTimeout(() => {
const newLastLineLength = editor.current.getLine(currentLine).length;
editor.current.focus();
editor.current.setCursor({ line: currentLine, ch: newLastLineLength });
}, 0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: highIf it breaks the basic use of the productsource: core:content-managerSource is core/content-manager packagestatus: pending reproductionWaiting for free time to reproduce the issue, or more informationversion: 5Issue is present in Strapi 5

    Type

    No type

    Projects

    Status

    To be reviewed

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions