Skip to content

Editor not restore the selection state after update value #727

@akaguny

Description

@akaguny

Reproduce example link: https://codesandbox.io/p/sandbox/react-codemirror-example-codemirror-6-forked-sj8ynr
Reproduce:

  1. open the example link
  2. select unmodified content or select all content (important: after update selection should not to be collapsed)
  3. click to the update content button

expected result: Editor selection restored
alternative expected result: Editor selection and browser selection not showed

actual result:

  1. Editor selection now showed
  2. Browser selection exist (green color of the text for demonstration)

demonstration:

editor.webm

workaround:
clear browser selection state before update editor state:

    const selection = window.getSelection();
    const range = selection?.getRangeAt(0);
    range?.collapse(true);

use collapse https://developer.mozilla.org/en-US/docs/Web/API/Selection/collapse as more safe way either empty https://developer.mozilla.org/en-US/docs/Web/API/Selection/empty

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions