Skip to content

Commit 54d8ef6

Browse files
authored
Feat/#319-K: 블럭 타입 변경 이후 입력된 / 제거 (#323)
* feat: 텍스트 블럭으로 변경 시 입력한 / 제거 props.type이 변경된 경우 readCRDT() 길이가 존재한다면 localDeleteCRDT(0) 실행 Resolves #319 * feat: / 지우는 로직에 타입 변경을 현재 유저가 했는지 확인하는 조건 추가
1 parent 5f0a5a3 commit 54d8ef6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

client/src/components/Block/TextBlock.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface BlockProps {
1818
onHandleBlock: React.KeyboardEventHandler;
1919
type: BlockType;
2020
setType: (arg: BlockType) => void;
21+
isLocalTypeUpdate: boolean;
2122
registerRef: (arg: React.RefObject<HTMLElement>) => void;
2223
}
2324

@@ -27,6 +28,7 @@ function TextBlock({
2728
onHandleBlock,
2829
type,
2930
setType,
31+
isLocalTypeUpdate,
3032
registerRef,
3133
}: BlockProps) {
3234
const { momSocket: socket } = useSocketContext();
@@ -135,6 +137,18 @@ function TextBlock({
135137
updateCaretPosition();
136138
}, [isOpen]);
137139

140+
useEffect(() => {
141+
if (isLocalTypeUpdate && readCRDT().length) {
142+
const remoteDeletion = localDeleteCRDT(0);
143+
socket.emit(BLOCK_EVENT.DELETE_TEXT, id, remoteDeletion);
144+
145+
if (!blockRef.current) return;
146+
147+
blockRef.current.innerText = readCRDT();
148+
blockRef.current.focus();
149+
}
150+
}, [type]);
151+
138152
// 로컬에서 일어나는 작성 - 삽입과 삭제 연산
139153
const onInput: React.FormEventHandler = (e) => {
140154
setOffset();

client/src/components/Block/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function Block({ id, index, onHandleBlock, registerRef }: BlockProps) {
6161
onHandleBlock={onHandleBlock}
6262
type={type}
6363
setType={setBlockType}
64+
isLocalTypeUpdate={localUpdateFlagRef.current}
6465
registerRef={registerRef}
6566
/>
6667
);

0 commit comments

Comments
 (0)