Skip to content

Commit

Permalink
Merge pull request #102 from boostcampwm-2024/Fix_진짜_린트_설정
Browse files Browse the repository at this point in the history
Style: 진짜 린트 설정함...
  • Loading branch information
Ludovico7 authored Nov 12, 2024
2 parents 8bb2d3d + 5d7c5b7 commit bab1050
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 50 deletions.
2 changes: 1 addition & 1 deletion client/src/features/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useRef, useState, useCallback, useEffect } from "react";
import { EditorState } from "../../types/markdown";
import { Block } from "@components/block/Block";
import { useCaretManager } from "@hooks/useCaretManager";
import { useKeyboardHandlers } from "@hooks/useMarkdownGrammer";
import { LinkedListBlock } from "@utils/linkedLIstBlock";
import { checkMarkdownPattern } from "@utils/markdownPatterns";
import { EditorState } from "../../types/markdown";
import {
editorContainer,
editorTitleContainer,
Expand Down
6 changes: 3 additions & 3 deletions client/src/hooks/useMarkdownGrammer/handlers/arrow.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from "react";
import { handleKeyNavigation } from "@utils/blockNavigationUtils";
import { EditorNode } from "../../../types/markdown";
import { KeyHandlerProps } from "./handlerProps";
import { handleKeyNavigation } from "@utils/blockNavigationUtils";

export const useArrowKeyHandler = ({
editorState,
Expand All @@ -19,10 +19,10 @@ export const useArrowKeyHandler = ({
case "ArrowUp":
case "ArrowDown": {
e.preventDefault();

const direction = e.key === "ArrowUp" ? "prev" : "next";
targetNode = handleKeyNavigation(currentNode, direction);

break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/hooks/useMarkdownGrammer/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useCallback } from "react";
import { KeyHandlerProps } from "./handlers/handlerProps";
import { useSpaceKeyHandler } from "./handlers/space";
import { useArrowKeyHandler } from "./handlers/arrow";
import { useBackspaceKeyHandler } from "./handlers/backSpace";
import { useEnterKeyHandler } from "./handlers/enter";
import { useArrowKeyHandler } from "./handlers/arrow";
import { KeyHandlerProps } from "./handlers/handlerProps";
import { useSpaceKeyHandler } from "./handlers/space";

export const useKeyboardHandlers = (props: KeyHandlerProps) => {
const handleEnter = useEnterKeyHandler(props);
Expand Down
85 changes: 42 additions & 43 deletions client/src/utils/blockNavigationUtils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { EditorNode } from "../types/markdown";

type NavigationDirection = 'prev' | 'next';
type NavigationDirection = "prev" | "next";

// 에디터 노드 타입 체크를 위한 유틸리티 함수들
// 에디터 노드 타입 체크를 위한 유틸리티 함수들
export const nodeTypeCheckers = {
isCheckbox: (node?: EditorNode | null): boolean => node?.type === 'checkbox',
isList: (node?: EditorNode | null): boolean => node?.type === 'ul' || node?.type === 'ol',
isListItem: (node?: EditorNode | null): boolean => node?.type === 'li',
isCheckbox: (node?: EditorNode | null): boolean => node?.type === "checkbox",
isList: (node?: EditorNode | null): boolean => node?.type === "ul" || node?.type === "ol",
isListItem: (node?: EditorNode | null): boolean => node?.type === "li",
isCheckboxChild: (node: EditorNode): boolean => nodeTypeCheckers.isCheckbox(node.parentNode),
};

// 리스트 관련 유틸리티 함수들
// 리스트 관련 유틸리티 함수들
export const listUtils = {
getFirstListItem: (node: EditorNode) => node.firstChild,
getLastListItem: (node: EditorNode) => {
if (!node.firstChild) return null;

let lastItem: EditorNode = node.firstChild;
while (lastItem.nextSibling?.id) {
lastItem = lastItem.nextSibling;
Expand All @@ -24,87 +24,86 @@ export const listUtils = {
},
};

// 체크박스 자식 노드의 이동 처리
// 체크박스 자식 노드의 이동 처리
const handleCheckboxChildNavigation = (
currentNode: EditorNode,
direction: NavigationDirection
currentNode: EditorNode,
direction: NavigationDirection,
): EditorNode | null => {
const parentCheckbox = currentNode.parentNode;
const targetNode = direction === 'prev' ? parentCheckbox?.prevNode : parentCheckbox?.nextNode;
const targetNode = direction === "prev" ? parentCheckbox?.prevNode : parentCheckbox?.nextNode;

if (!targetNode) return null;

if (nodeTypeCheckers.isCheckbox(targetNode)) {
return targetNode.firstChild ?? null;
}

if (nodeTypeCheckers.isList(targetNode)) {
return direction === 'prev'
return direction === "prev"
? listUtils.getLastListItem(targetNode)
: listUtils.getFirstListItem(targetNode);
}

return targetNode;
};

// 리스트 아이템 노드의 이동 처리
// 리스트 아이템 노드의 이동 처리
const handleListItemNavigation = (
currentNode: EditorNode,
direction: NavigationDirection
currentNode: EditorNode,
direction: NavigationDirection,
): EditorNode | null => {
const sibling = direction === 'prev' ? currentNode.prevSibling : currentNode.nextSibling;
const sibling = direction === "prev" ? currentNode.prevSibling : currentNode.nextSibling;

if (sibling?.id) {
return sibling;
}

const parentSibling = direction === 'prev'
? currentNode.parentNode?.prevNode
: currentNode.parentNode?.nextNode;


const parentSibling =
direction === "prev" ? currentNode.parentNode?.prevNode : currentNode.parentNode?.nextNode;

if (!parentSibling) return null;

if (nodeTypeCheckers.isCheckbox(parentSibling)) {
return parentSibling.firstChild ?? null;
}

return parentSibling;
};

// 기본 블록 노드의 이동 처리
// 기본 블록 노드의 이동 처리
const handleBasicBlockNavigation = (
currentNode: EditorNode,
direction: NavigationDirection
currentNode: EditorNode,
direction: NavigationDirection,
): EditorNode | null => {
const targetNode = direction === 'prev' ? currentNode.prevNode : currentNode.nextNode;
const targetNode = direction === "prev" ? currentNode.prevNode : currentNode.nextNode;

if (!targetNode) return null;

if (nodeTypeCheckers.isCheckbox(targetNode)) {
return targetNode.firstChild ?? null;
}

if (nodeTypeCheckers.isList(targetNode)) {
return direction === 'prev'
return direction === "prev"
? listUtils.getLastListItem(targetNode)
: listUtils.getFirstListItem(targetNode);
}

return targetNode;
};

// 키보드 네비게이션 핸들러 -> 현재 노드와 이동 방향을 받아 다음 타겟 노드를 반환
// 키보드 네비게이션 핸들러 -> 현재 노드와 이동 방향을 받아 다음 타겟 노드를 반환
export const handleKeyNavigation = (
currentNode: EditorNode,
direction: NavigationDirection
currentNode: EditorNode,
direction: NavigationDirection,
): EditorNode | null => {
if (nodeTypeCheckers.isCheckboxChild(currentNode)) {
return handleCheckboxChildNavigation(currentNode, direction);
}

if (nodeTypeCheckers.isListItem(currentNode)) {
return handleListItemNavigation(currentNode, direction);
}

return handleBasicBlockNavigation(currentNode, direction);
};
};

0 comments on commit bab1050

Please sign in to comment.