uiwjs / uiwjs/react-codemirror
Editor not restore the selection state after update value
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:
- open the example link
- select unmodified content or select all content (important: after update selection should not to be collapsed)
- click to the update content button
expected result: Editor selection restored
alternative expected result: Editor selection and browser selection not showed
actual result:
- Editor selection now showed
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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