uiwjs / uiwjs/react-codemirror

Editor not restore the selection state after update value

Open
#727 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

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:

https://github.com/user-attachments/assets/849dd600-6da5-4e76-9ccd-93fae7ed90f2

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and inspect how the React editor handles the update content button and selection state. Reproduce the browser selection issue, then verify that updating content either restores the editor selection or leaves neither editor nor browser selection visible.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.