mirror of
https://github.com/stablyai/orca
synced 2026-04-21 14:17:16 +00:00
Fix cursor jump when typing in markdown list items (#658)
The debounced onUpdate serialization feeds back through the content prop, and if the user types between the debounce firing and the useEffect running, the stale prop triggers setContent — resetting the cursor. Skip the destructive setContent when the content prop matches our own last serialization (lastCommittedMarkdownRef).
This commit is contained in:
parent
e7f973339a
commit
92353e7233
1 changed files with 11 additions and 0 deletions
|
|
@ -443,6 +443,17 @@ export default function RichMarkdownEditor({
|
|||
return
|
||||
}
|
||||
|
||||
// Why: the debounced onUpdate serializes the editor and feeds it back
|
||||
// through onContentChange → editorDrafts → the content prop. If the
|
||||
// user typed between the debounce firing and this effect running, the
|
||||
// editor already contains newer content than the prop. Comparing
|
||||
// against lastCommittedMarkdownRef (which is set in the same tick as
|
||||
// onContentChange) lets us recognise our own serialization and skip the
|
||||
// destructive setContent that would reset the cursor mid-typing.
|
||||
if (content === lastCommittedMarkdownRef.current) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentMarkdown = editor.getMarkdown()
|
||||
if (currentMarkdown === content) {
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue