From 36ed1212c09cd6786deb1a3de91f8410f013a647 Mon Sep 17 00:00:00 2001 From: Jonathan Fok kan Date: Thu, 22 May 2025 21:33:22 -0400 Subject: [PATCH 1/2] fix(editor): Prevent race condition and ensure correct list continuation on Enter _ --- web/src/components/MemoEditor/Editor/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/src/components/MemoEditor/Editor/index.tsx b/web/src/components/MemoEditor/Editor/index.tsx index 19381557822b1..60186cb3a5d4e 100644 --- a/web/src/components/MemoEditor/Editor/index.tsx +++ b/web/src/components/MemoEditor/Editor/index.tsx @@ -169,6 +169,10 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef< if (event.shiftKey || event.ctrlKey || event.metaKey || event.altKey) { return; } + // Prevent a newline from being inserted, so that we can insert it manually later. + // This prevents a race condition that occurs between the newline insertion and + // inserting the insertText. + event.preventDefault() const cursorPosition = editorActions.getCursorPosition(); const prevContent = editorActions.getContent().substring(0, cursorPosition); @@ -206,7 +210,7 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef< } if (insertText) { - editorActions.insertText(insertText); + editorActions.insertText("\n" + insertText); } } }; From a58da4e164f9786dbb2d2b7f058f3fb0ee0d303c Mon Sep 17 00:00:00 2001 From: Jonathan Fok kan Date: Mon, 26 May 2025 21:05:52 -0400 Subject: [PATCH 2/2] fix: always insert newline after preventing default Enter key behavior --- web/src/components/MemoEditor/Editor/index.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/web/src/components/MemoEditor/Editor/index.tsx b/web/src/components/MemoEditor/Editor/index.tsx index 60186cb3a5d4e..35c02909c0069 100644 --- a/web/src/components/MemoEditor/Editor/index.tsx +++ b/web/src/components/MemoEditor/Editor/index.tsx @@ -172,7 +172,8 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef< // Prevent a newline from being inserted, so that we can insert it manually later. // This prevents a race condition that occurs between the newline insertion and // inserting the insertText. - event.preventDefault() + // Needs to be called before any async call. + event.preventDefault(); const cursorPosition = editorActions.getCursorPosition(); const prevContent = editorActions.getContent().substring(0, cursorPosition); @@ -209,9 +210,7 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef< insertText += " |"; } - if (insertText) { - editorActions.insertText("\n" + insertText); - } + editorActions.insertText("\n" + insertText); } };