File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { useSetRecoilState } from 'recoil' ;
2
- import { blockMapState , pagesState , focusState } from '@/stores' ;
2
+ import { blockMapState , pagesState } from '@/stores' ;
3
3
import { pageIO , pageListIO } from '@/socket' ;
4
4
import { BlockMap , Page } from '@/schemes' ;
5
5
import { useEffect } from 'react' ;
@@ -33,6 +33,18 @@ const useSocket = () => {
33
33
} ) ;
34
34
35
35
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
+ }
36
48
setBlockMap ( updatedBlockMap ) ;
37
49
} ) ;
38
50
You can’t perform that action at this time.
0 commit comments