Skip to content

Commit

Permalink
feat: 단축키로 텍스트 스타일 변경 구현
Browse files Browse the repository at this point in the history
Co-authored-by: hyonun <[email protected]>
Co-authored-by: Jang seo yun <[email protected]>
  • Loading branch information
3 people committed Dec 2, 2024
1 parent f5842ee commit 3f44e4f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion client/src/features/editor/components/block/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@ export const Block: React.FC<BlockProps> = memo(
}
};

const handleKeyDown = (
e: React.KeyboardEvent<HTMLDivElement>,
blockRef: HTMLDivElement | null,
block: CRDTBlock,
) => {
switch (e.key) {
case e.metaKey && "b": {
e.preventDefault();
onTextStyleUpdate("bold", block.id, selectedNodes);
break;
}
case e.metaKey && "i": {
e.preventDefault();
onTextStyleUpdate("italic", block.id, selectedNodes);
break;
}
case e.metaKey && "u": {
e.preventDefault();
onTextStyleUpdate("underline", block.id, selectedNodes);
break;
}
case e.metaKey && "Shift" && "s": {
onTextStyleUpdate("strikethrough", block.id, selectedNodes);
e.preventDefault();
break;
}
default: {
onKeyDown(e, blockRef, block);
break;
}
}
};

const handleAnimationSelect = (animation: AnimationType) => {
onAnimationSelect(block.id, animation);
};
Expand Down Expand Up @@ -276,7 +309,7 @@ export const Block: React.FC<BlockProps> = memo(
<IconBlock type={block.type} index={block.listIndex} indent={block.indent} />
<div
ref={blockRef}
onKeyDown={(e) => onKeyDown(e, blockRef.current, block)}
onKeyDown={(e) => handleKeyDown(e, blockRef.current, block)}
onInput={handleInput}
onClick={(e) => onClick(block.id, e)}
onCopy={(e) => onCopy(e, blockRef.current, block)}
Expand Down

0 comments on commit 3f44e4f

Please sign in to comment.