From 92353e7233b6b995092a2b5119d55d520ecba5d2 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Tue, 14 Apr 2026 16:09:49 -0700 Subject: [PATCH] Fix cursor jump when typing in markdown list items (#658) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- .../src/components/editor/RichMarkdownEditor.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/renderer/src/components/editor/RichMarkdownEditor.tsx b/src/renderer/src/components/editor/RichMarkdownEditor.tsx index 52fa14256..efad157a2 100644 --- a/src/renderer/src/components/editor/RichMarkdownEditor.tsx +++ b/src/renderer/src/components/editor/RichMarkdownEditor.tsx @@ -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