Skip to content

Commit 8e45505

Browse files
committed
[#153] feat: 실시간 동기화 시 기존 caret이 적용되도록 수정
1 parent 2203d90 commit 8e45505

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

frontend/src/hooks/useSocket.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useSetRecoilState } from 'recoil';
2-
import { blockMapState, pagesState, focusState } from '@/stores';
2+
import { blockMapState, pagesState } from '@/stores';
33
import { pageIO, pageListIO } from '@/socket';
44
import { BlockMap, Page } from '@/schemes';
55
import { useEffect } from 'react';
@@ -33,6 +33,18 @@ const useSocket = () => {
3333
});
3434

3535
pageIO.on('PageUpdate', (updatedBlockMap: BlockMap) => {
36+
const { focusOffset: beforeOffset, focusNode } = window.getSelection();
37+
const length = (focusNode as any)?.length;
38+
if (length) {
39+
focusNode.parentElement.blur();
40+
setTimeout(() => {
41+
const sel = window.getSelection();
42+
sel.collapse(
43+
sel.focusNode,
44+
beforeOffset < length ? beforeOffset : length,
45+
);
46+
});
47+
}
3648
setBlockMap(updatedBlockMap);
3749
});
3850

0 commit comments

Comments
 (0)