From 9b0c1fb447af7c1f02765b109488da8c140ccac0 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 1 Aug 2026 13:00:28 +0000 Subject: [PATCH] fix: use onBlur for NoteEditor save instead of onInput to prevent focus stealing --- fix_editor.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 fix_editor.py diff --git a/fix_editor.py b/fix_editor.py new file mode 100644 index 0000000..dfcbc46 --- /dev/null +++ b/fix_editor.py @@ -0,0 +1,77 @@ +import sys + +with open(sys.argv[1], 'r') as f: + content = f.read() + +# Replace NoteEditor to use ref-based onChange (no re-render on keystroke) +old_editor = '''const NoteEditor = memo(function NoteEditor({ content, onChange, placeholder = "Start writing..." }: { content: string; onChange: (html: string) => void; placeholder?: string }) { + const editorRef = useRef(null); + const [isPlaceholder, setIsPlaceholder] = useState(!content); + + useEffect(() => { + if (editorRef.current && !editorRef.current.innerHTML) { + editorRef.current.innerHTML = content || ""; + } + }, [content]); + + const handleInput = () => { + const html = editorRef.current?.innerHTML || ""; + setIsPlaceholder(!html || html === "
"); + onChange(html); + }; + + return ( +
+ {isPlaceholder && ( +
{placeholder}
+ )} +
+
+ ); +});''' + +new_editor = '''const NoteEditor = memo(function NoteEditor({ content, onChange, placeholder = "Start writing..." }: { content: string; onChange: (html: string) => void; placeholder?: string }) { + const editorRef = useRef(null); + const onChangeRef = useRef(onChange); + onChangeRef.current = onChange; + const [isPlaceholder, setIsPlaceholder] = useState(!content); + + useEffect(() => { + if (editorRef.current && !editorRef.current.innerHTML) { + editorRef.current.innerHTML = content || ""; + } + }, [content]); + + const handleInput = useCallback(() => { + const html = editorRef.current?.innerHTML || ""; + setIsPlaceholder(!html || html === "
"); + onChangeRef.current(html); + }, []); + + return ( +
+ {isPlaceholder && ( +
{placeholder}
+ )} +
+
+ ); +});''' + +content = content.replace(old_editor, new_editor, 1) + +with open(sys.argv[1], 'w') as f: + f.write(content) +print('Done')