fix: automatic indentation follows previous lines in lists (#4048) (#4050)

* fix: automatic indentation follows previous lines in lists (#4048)

* fix: automatic indentation follows previous lines in lists (#4048)
change the position of this logic and recommit it
This commit is contained in:
new-aspect 2024-10-25 19:16:59 +08:00 committed by GitHub
parent 2851f11302
commit aa9649adf0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -164,7 +164,11 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<
return;
}
let insertText = "";
// Get the indentation of the previous line
const lines = prevContent.split("\n");
const lastLine = lines[lines.length - 1];
const indentationMatch = lastLine.match(/^\s*/);
let insertText = indentationMatch ? indentationMatch[0] : ""; // Keep the indentation of the previous line
if (lastNode.type === NodeType.TASK_LIST_ITEM) {
const { symbol } = lastNode.taskListItemNode as TaskListItemNode;
insertText = `${symbol} [ ] `;