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

feat: 마크다운 편집기 사용성 개선 #624

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kyujenius
Copy link

@Kyujenius Kyujenius commented Mar 7, 2025

작업 계기

외부 마크다운 편집기 혹은 대다수의 IDE 에서는 특정 텍스트들을 드래깅 후에, 특정 키를 누르면, 자주 사용하는 경우에는 감싸주게끔 설계되어있습니다. 따라서 다음과 같은 키들을 누를 때, 텍스트를 감싸줄 수 있게끔 도와줍니다. 현재는 드래그 후에 해당 키를 누를 시에 기존의 텍스트가 바로 덮어씌워지며 사용자 경험에 좋지 않습니다.

  1. ` 키
  2. < 키
  3. [ 키
  4. ( 키
  5. { 키
  6. Cmd/Ctrl + B - 볼드체
  7. Cmd/Ctrl + I - 이탈릭체
  8. Cmd/Ctrl + Shift + S - 취소선
    this.codemirror.on('keydown', (cm, e) => {
      const { key, ctrlKey, metaKey, shiftKey } = e;
      const doc = cm.getDoc();
      const selection = doc.getSelection();

      if (!selection) return;

      if (key === '`' && !ctrlKey && !metaKey) {
        if (selection.length > 0) {
          e.preventDefault();
          doc.replaceSelection(`\`${selection}\``);
          return;
        }
      }

      if ((ctrlKey || metaKey) && key === 'b') {
        e.preventDefault();
        doc.replaceSelection(`**${selection}**`);
        return;
      }

      if ((ctrlKey || metaKey) && key === 'i') {
        e.preventDefault();
        doc.replaceSelection(`_${selection}_`);
        return;
      }

      if ((ctrlKey || metaKey) && shiftKey && key === 's') {
        e.preventDefault();
        doc.replaceSelection(`~~${selection}~~`);
        return;
      }

      if (key === '[') {
        e.preventDefault();
        doc.replaceSelection(`[${selection}]`);
        return;
      }

      if (key === '(') {
        e.preventDefault();
        doc.replaceSelection(`(${selection})`);
        return;
      }

      if (key === '{') {
        e.preventDefault();
        doc.replaceSelection(`{${selection}}`);
        return;
      }

      if (key === '<') {
        e.preventDefault();
        doc.replaceSelection(`<${selection}>`);
        return;
      }
    });

Velog 시작한 지 얼마 안 됐는데...! PR이 반려되더라도 해당 기능 추가되면 너무 좋을 거 같아요 감사합니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant