fix: In MonacoEditor the caret jumps to the start#264
Conversation
📝 WalkthroughWalkthroughThe Monaco editor's value synchronization was refactored from a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
cb35b38 to
bd30e7a
Compare
bd30e7a to
64d3ea9
Compare
64d3ea9 to
323894c
Compare
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Closes #228
When the user types text, a is triggered a code to update the note text. After the note updates, the Monaco editor compares its own current editor content with the updated note text — if they differ,
setValueis called to update editor content.On Ubuntu, the note text was sometimes one character behind the editor content. This caused editor content updates to be called unnecessarily, which reset the cursor position. It is unclear why this happens on Ubuntu but not on other systems.
The fix was to replace
useEffectwithuseLayoutEffect. It runs after React has applied the state change, but before the browser has painted the frame. At that point the browser is blocked and no new input events can arrive — the note text is to be up to date.Fix:
monaco.mp4
Bug:
monaco_bug_2.mp4
Summary by CodeRabbit