From aa9649adf0fcb683f93609aad6bfa31fabca3dfa Mon Sep 17 00:00:00 2001 From: new-aspect <73388965+new-aspect@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:16:59 +0800 Subject: [PATCH] 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 --- 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 fa56b729..749b7068 100644 --- a/web/src/components/MemoEditor/Editor/index.tsx +++ b/web/src/components/MemoEditor/Editor/index.tsx @@ -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} [ ] `;