diff --git a/resources/logo-full.webp b/resources/logo-full.webp index 0bbbeb12..fecae6c6 100644 Binary files a/resources/logo-full.webp and b/resources/logo-full.webp differ diff --git a/resources/logo.webp b/resources/logo.webp index 323faa34..ecf7c441 100644 Binary files a/resources/logo.webp and b/resources/logo.webp differ diff --git a/web/public/logo-full.webp b/web/public/logo-full.webp index 0bbbeb12..fecae6c6 100644 Binary files a/web/public/logo-full.webp and b/web/public/logo-full.webp differ diff --git a/web/public/logo.webp b/web/public/logo.webp index 323faa34..ecf7c441 100644 Binary files a/web/public/logo.webp and b/web/public/logo.webp differ diff --git a/web/src/components/ArchivedMemo.tsx b/web/src/components/ArchivedMemo.tsx index 89822607..d7c88bd2 100644 --- a/web/src/components/ArchivedMemo.tsx +++ b/web/src/components/ArchivedMemo.tsx @@ -1,4 +1,4 @@ -import { IMAGE_URL_REG } from "../helpers/consts"; +import { IMAGE_URL_REG } from "../helpers/marked"; import * as utils from "../helpers/utils"; import useI18n from "../hooks/useI18n"; import useToggle from "../hooks/useToggle"; diff --git a/web/src/components/Editor/Editor.tsx b/web/src/components/Editor/Editor.tsx index 4055470a..fd953264 100644 --- a/web/src/components/Editor/Editor.tsx +++ b/web/src/components/Editor/Editor.tsx @@ -10,6 +10,7 @@ export interface EditorRefActions { insertText: (text: string) => void; setContent: (text: string) => void; getContent: () => string; + getCursorPosition: () => number; } interface EditorProps { @@ -64,14 +65,17 @@ const Editor = forwardRef((props: EditorProps, ref: React.ForwardedRef { if (editorRef.current) { editorRef.current.value = text; + editorRef.current.focus(); handleContentChangeCallback(editorRef.current.value); refresh(); } @@ -79,6 +83,9 @@ const Editor = forwardRef((props: EditorProps, ref: React.ForwardedRef { return editorRef.current?.value ?? ""; }, + getCursorPosition: (): number => { + return editorRef.current?.selectionStart ?? 0; + }, }), [] ); diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index 68cc045c..bc0c0c59 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -4,8 +4,8 @@ import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; import "dayjs/locale/zh"; import useI18n from "../hooks/useI18n"; -import { IMAGE_URL_REG, UNKNOWN_ID } from "../helpers/consts"; -import { DONE_BLOCK_REG, formatMemoContent, TODO_BLOCK_REG } from "../helpers/marked"; +import { UNKNOWN_ID } from "../helpers/consts"; +import { DONE_BLOCK_REG, formatMemoContent, IMAGE_URL_REG, TODO_BLOCK_REG } from "../helpers/marked"; import { editorStateService, locationService, memoService, userService } from "../services"; import Icon from "./Icon"; import Only from "./common/OnlyWhen"; diff --git a/web/src/components/MemoCardDialog.tsx b/web/src/components/MemoCardDialog.tsx index 277fb201..4d4e6fff 100644 --- a/web/src/components/MemoCardDialog.tsx +++ b/web/src/components/MemoCardDialog.tsx @@ -1,9 +1,9 @@ import { useState, useEffect, useCallback } from "react"; import { editorStateService, memoService, userService } from "../services"; import { useAppSelector } from "../store"; -import { IMAGE_URL_REG, MEMO_LINK_REG, UNKNOWN_ID, VISIBILITY_SELECTOR_ITEMS } from "../helpers/consts"; +import { UNKNOWN_ID, VISIBILITY_SELECTOR_ITEMS } from "../helpers/consts"; import * as utils from "../helpers/utils"; -import { formatMemoContent, parseHtmlToRawText } from "../helpers/marked"; +import { formatMemoContent, IMAGE_URL_REG, MEMO_LINK_REG, parseHtmlToRawText } from "../helpers/marked"; import Only from "./common/OnlyWhen"; import toastHelper from "./Toast"; import { generateDialog } from "./Dialog"; diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx index d2188667..8df8234a 100644 --- a/web/src/components/MemoEditor.tsx +++ b/web/src/components/MemoEditor.tsx @@ -179,6 +179,34 @@ const MemoEditor: React.FC = () => { setEditorContentCache(content); }, []); + const handleCheckBoxBtnClick = () => { + if (!editorRef.current) { + return; + } + + const cursorPosition = editorRef.current.getCursorPosition(); + const prevValue = editorRef.current.getContent().slice(0, cursorPosition); + if (prevValue === "" || prevValue.endsWith("\n")) { + editorRef.current?.insertText("- [ ] "); + } else { + editorRef.current?.insertText("\n- [ ] "); + } + }; + + const handleCodeBlockBtnClick = () => { + if (!editorRef.current) { + return; + } + + const cursorPosition = editorRef.current.getCursorPosition(); + const prevValue = editorRef.current.getContent().slice(0, cursorPosition); + if (prevValue === "" || prevValue.endsWith("\n")) { + editorRef.current?.insertText("```\n\n```"); + } else { + editorRef.current?.insertText("\n```\n\n```"); + } + }; + const handleUploadFileBtnClick = useCallback(() => { const inputEl = document.createElement("input"); inputEl.type = "file"; @@ -258,6 +286,12 @@ const MemoEditor: React.FC = () => { )} + +