Skip to content

Commit c75b52b

Browse files
committed
fix(editor): Prevent race condition and ensure correct list continuation on Enter
1 parent 2a92baf commit c75b52b

File tree

1 file changed

+5
-1
lines changed
  • web/src/components/MemoEditor/Editor

1 file changed

+5
-1
lines changed

web/src/components/MemoEditor/Editor/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<
169169
if (event.shiftKey || event.ctrlKey || event.metaKey || event.altKey) {
170170
return;
171171
}
172+
// Prevent a newline from being inserted, so that we can insert it manually later.
173+
// This prevents a race condition that occurs sometimes where the newline can be
174+
// inserted before the insertText.
175+
event.preventDefault()
172176

173177
const cursorPosition = editorActions.getCursorPosition();
174178
const prevContent = editorActions.getContent().substring(0, cursorPosition);
@@ -194,7 +198,7 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<
194198
insertText += `${Number(number) + 1}. `;
195199
}
196200
if (insertText) {
197-
editorActions.insertText(insertText);
201+
editorActions.insertText("\n" + insertText);
198202
}
199203
}
200204
};

0 commit comments

Comments
 (0)