Skip to content

fix(editor): Prevent race condition and ensure correct list continuation on Enter #4716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions web/src/components/MemoEditor/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ 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.
// Needs to be called before any async call.
event.preventDefault();

const cursorPosition = editorActions.getCursorPosition();
const prevContent = editorActions.getContent().substring(0, cursorPosition);
Expand Down Expand Up @@ -205,9 +210,7 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<
insertText += " |";
}

if (insertText) {
editorActions.insertText(insertText);
}
editorActions.insertText("\n" + insertText);
}
};

Expand Down