mirror of
https://github.com/usememos/memos.git
synced 2025-10-17 01:37:02 +08:00
fix(editor): prevent race condition and ensure correct list continuation on Enter (#4716)
* fix(editor): Prevent race condition and ensure correct list continuation on Enter _ * fix: always insert newline after preventing default Enter key behavior
This commit is contained in:
parent
d76f988bb5
commit
7c05a9b997
1 changed files with 6 additions and 3 deletions
|
@ -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);
|
||||
|
@ -205,9 +210,7 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<
|
|||
insertText += " |";
|
||||
}
|
||||
|
||||
if (insertText) {
|
||||
editorActions.insertText(insertText);
|
||||
}
|
||||
editorActions.insertText("\n" + insertText);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue