Repository: usememos/memos
File: web/src/components/MemoEditor.tsx (TypeScript)

Code before:
    }

    if (event.ctrlKey || event.metaKey) {
      if (event.key === "Enter") {
        handleSaveBtnClick();
        return;
      }
      if (event.key === "b") {
        event.preventDefault();
        editorRef.current.insertText("", "**", "**");
        return;
      }
      if (event.key === "i") {
        event.preventDefault();
        editorRef.current.insertText("", "*", "*");
        return;
      }
      if (event.key === "e") {
        event.preventDefault();
        editorRef.current.insertText("", "`", "`");
        return;
      }
      if (event.key === "k") {
        event.preventDefault();
        const selectedContent = editorRef.current.getSelectedContent();
        editorRef.current.insertText("", "[", "]()");
        const pos = editorRef.current.getCursorPosition();
        if (selectedContent) {
          editorRef.current.setCursorPosition(pos + 2);
        }
      }
    }

    if (event.key === "Enter") {
      const cursorPosition = editorRef.current.getCursorPosition();
      const contentBeforeCursor = editorRef.current.getContent().slice(0, cursorPosition);
      const rowValue = last(contentBeforeCursor.split("\n"));
      if (rowValue) {
        if (listItemSymbolList.includes(rowValue) || emptyOlReg.test(rowValue)) {
          event.preventDefault();
          editorRef.current.removeText(cursorPosition - rowValue.length, rowValue.length);
        } else {
          // unordered/todo list
          let matched = false;
          for (const listItemSymbol of listItemSymbolList) {
            if (rowValue.startsWith(listItemSymbol)) {
              event.preventDefault();
              editorRef.current.insertText("", `\n${listItemSymbol}`);
              matched = true;
              break;
            }

Review comment (suggestion):
```suggestion
        editorRef.current.insertText("", "[", "](url)");
```
<img width="260" alt="image" src="https://user-images.githubusercontent.com/24653555/208636372-e5239349-9493-4b96-8472-de3d5de49bc7.png">


Code after:
    }

    if (event.ctrlKey || event.metaKey) {
      if (event.key === "Enter") {
        handleSaveBtnClick();
        return;
      }
      if (event.key === "b") {
        event.preventDefault();
        editorRef.current.insertText("", "**", "**");
        return;
      }
      if (event.key === "i") {
        event.preventDefault();
        editorRef.current.insertText("", "*", "*");
        return;
      }
      if (event.key === "e") {
        event.preventDefault();
        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") {
      const cursorPosition = editorRef.current.getCursorPosition();
      const contentBeforeCursor = editorRef.current.getContent().slice(0, cursorPosition);
      const rowValue = last(contentBeforeCursor.split("\n"));
      if (rowValue) {
        if (listItemSymbolList.includes(rowValue) || emptyOlReg.test(rowValue)) {
          event.preventDefault();
          editorRef.current.removeText(cursorPosition - rowValue.length, rowValue.length);
        } else {
          // unordered/todo list
          let matched = false;
          for (const listItemSymbol of listItemSymbolList) {
            if (rowValue.startsWith(listItemSymbol)) {
              event.preventDefault();
              editorRef.current.insertText("", `\n${listItemSymbol}`);
              matched = true;
              break;