Skip to content

Commit 8078d26

Browse files
authored
Merge branch 'dev' into style/#271-K
2 parents f7c7253 + cf902bf commit 8078d26

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

β€Žclient/src/components/Block/TextBlock.tsxβ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ function TextBlock({
110110

111111
// crdt의 μ΄ˆκΈ°ν™”μ™€ μ†ŒμΌ“μ„ 톡해 μ „λ‹¬λ°›λŠ” 리λͺ¨νŠΈ μ—°μ‚° 처리
112112
useEffect(() => {
113-
registerRef(blockRef);
114-
115113
socket.emit(BLOCK_EVENT.INIT, id);
116114

117115
ee.on(`${BLOCK_EVENT.INIT}-${id}`, onInitialize);
@@ -127,6 +125,10 @@ function TextBlock({
127125
};
128126
}, []);
129127

128+
useEffect(() => {
129+
registerRef(blockRef);
130+
}, [index]);
131+
130132
useEffect(() => {
131133
updateCaretPosition();
132134
}, [isOpen]);
@@ -240,7 +242,7 @@ function TextBlock({
240242
{
241243
ref: blockRef,
242244
'data-id': id,
243-
'date-index': index,
245+
'data-index': index,
244246
...commonHandlers,
245247
contentEditable: true,
246248
suppressContentEditableWarning: true,

β€Žclient/src/components/Mom/index.tsxβ€Ž

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Mom() {
2727
const titleRef = useRef<HTMLHeadingElement>(null);
2828

2929
const onTitleUpdate: React.FormEventHandler<HTMLHeadingElement> = useDebounce(
30-
(e) => {
30+
() => {
3131
if (!titleRef.current) return;
3232

3333
const title = titleRef.current.innerText;
@@ -46,13 +46,13 @@ function Mom() {
4646
focusIndex.current = idx;
4747
};
4848

49-
const setBlockFocus = () => {
49+
const setBlockFocus = (index: number) => {
5050
if (!blockRefs.current || focusIndex.current === undefined) return;
5151

5252
const idx = focusIndex.current;
53+
if (index === undefined || index !== idx) return;
5354

5455
const targetBlock = blockRefs.current[idx];
55-
5656
if (!targetBlock || !targetBlock.current) return;
5757

5858
targetBlock.current.focus();
@@ -104,17 +104,16 @@ function Mom() {
104104
updateBlockFocus(index - 1);
105105

106106
setBlocks(spreadCRDT());
107-
setBlockFocus();
107+
108+
if (focusIndex.current === undefined) return;
109+
setBlockFocus(focusIndex.current);
110+
108111
setCaretToEnd();
109112

110113
socket.emit(MOM_EVENT.DELETE_BLOCK, id, remoteDeletion);
111114
}
112115
};
113116

114-
useEffect(() => {
115-
setBlockFocus();
116-
}, [blocks]);
117-
118117
useEffect(() => {
119118
if (!selectedMom) return;
120119

@@ -184,6 +183,12 @@ function Mom() {
184183
};
185184
}, [selectedMom]);
186185

186+
const registerRef =
187+
(index: number) => (ref: React.RefObject<HTMLElement>) => {
188+
blockRefs.current[index] = ref;
189+
setBlockFocus(index);
190+
};
191+
187192
return selectedMom ? (
188193
<div className={style['mom-container']}>
189194
<div className={style['mom']}>
@@ -206,9 +211,7 @@ function Mom() {
206211
id={id}
207212
index={index}
208213
onHandleBlock={onHandleBlock}
209-
registerRef={(ref: React.RefObject<HTMLElement>) => {
210-
blockRefs.current[index] = ref;
211-
}}
214+
registerRef={registerRef(index)}
212215
/>
213216
))}
214217
</div>

β€Žclient/src/hooks/useOffset.tsxβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ export function useOffset(blockRef: React.RefObject<HTMLParagraphElement>) {
5454
};
5555

5656
const offsetHandlers = {
57-
onFocus:
58-
setOffset as unknown as React.FocusEventHandler<HTMLParagraphElement>,
5957
onClick:
6058
setOffset as unknown as React.MouseEventHandler<HTMLParagraphElement>,
6159
onKeyUp: onArrowKeyup,

0 commit comments

Comments
Β (0)