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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user