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.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
feat: support `command + k` shortcuts insert []() (#793)
ChasLui2658b1fd09e3
diff --git a/web/src/components/Editor/Editor.tsx b/web/src/components/Editor/Editor.tsxindex 110accd64..5228fbf12 100644--- a/web/src/components/Editor/Editor.tsx+++ b/web/src/components/Editor/Editor.tsx@@ -9,7 +9,7 @@ export interface EditorRefActions {getContent: () => string;getSelectedContent: () => string;getCursorPosition: () => number;- setCursorPosition: (pos: number) => void;+ setCursorPosition: (startPos: number, endPos?: number) => void;}interface Props {@@ -105,8 +105,9 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<const end = editorRef.current?.selectionEnd;return editorRef.current?.value.slice(start, end) ?? "";},- setCursorPosition: (pos: number) => {- editorRef.current?.setSelectionRange(pos, pos);+ setCursorPosition: (startPos: number, endPos?: number) => {+ const _endPos = isNaN(endPos as number) ? startPos : (endPos as number);+ editorRef.current?.setSelectionRange(startPos, _endPos);},}),[]diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsxindex 709c5d7e7..a1d0a5cff 100644--- a/web/src/components/MemoEditor.tsx+++ b/web/src/components/MemoEditor.tsx@@ -122,6 +122,16 @@ const MemoEditor = () => {editorRef.current.insertText("", "`", "`");return;}+ if (event.key === "k") {+ event.preventDefault();+ const selectedContent = editorRef.current.getSelectedContent();+ editorRef.current.insertText("", "[", "](url)");+ if (selectedContent) {+ const startPos = editorRef.current.getCursorPosition() + 2;+ const endPos = startPos + 3;+ editorRef.current.setCursorPosition(startPos, endPos);+ }+ }}if (event.key === "Enter") {