Skip to content
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

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

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion web/src/components/MemoEditor/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<

const cursorPosition = editorActions.getCursorPosition();
const prevContent = editorActions.getContent().substring(0, cursorPosition);
const lines = prevContent.split("\n");
const lastLine = lines[lines.length - 1];

// Get the indentation of the previous line
const indentationMatch = lastLine.match(/^\s*/);
const indentation = indentationMatch ? indentationMatch[0] : "";
const { nodes } = await markdownServiceClient.parseMarkdown({ markdown: prevContent });
const lastNode = last(last(nodes)?.listNode?.children);
if (!lastNode) {
return;
}

let insertText = "";
let insertText = indentation; // Keep the indentation of the previous line
if (lastNode.type === NodeType.TASK_LIST_ITEM) {
const { symbol } = lastNode.taskListItemNode as TaskListItemNode;
insertText = `${symbol} [ ] `;
Expand Down