Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: auto continuation list in editor (#689)

Zeng199836b92ad88493
diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx
index b8afe3d49..a0c6bd101 100644
--- a/web/src/components/MemoEditor.tsx
+++ b/web/src/components/MemoEditor.tsx
@@ -91,6 +91,29 @@ const MemoEditor = () => {
}, [editorState.editMemoId]);
const handleKeyDown = (event: React.KeyboardEvent) => {
+ if (event.key === "Enter") {
+ if (!editorRef.current) {
+ return;
+ }
+ const cursorPosition = editorRef.current.getCursorPosition();
+ const prevValue = editorRef.current.getContent().slice(0, cursorPosition);
+ const prevRows = prevValue.split("\n");
+ const prevRowValue = prevRows[prevRows.length - 1];
+ if (prevRowValue === "- " || prevRowValue === "- [ ] " || prevRowValue === "- [x] " || prevRowValue === "- [X] ") {
+ event.preventDefault();
+ prevRows[prevRows.length - 1] = "";
+ editorRef.current.setContent(prevRows.join("\n"));
+ } else {
+ if (prevRowValue.startsWith("- [ ] ") || prevRowValue.startsWith("- [x] ") || prevRowValue.startsWith("- [X] ")) {
+ event.preventDefault();
+ editorRef.current.insertText("", "\n- [ ] ");
+ } else if (prevRowValue.startsWith("- ")) {
+ event.preventDefault();
+ editorRef.current.insertText("", "\n- ");
+ }
+ }
+ return;
+ }
if (event.key === "Escape") {
if (state.fullscreen) {
handleFullscreenBtnClick();