| 
														
															@@ -17,6 +17,8 @@ import { rangeActions } from '$app_reducers/document/slice'; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import { RootState } from '$app/stores/store'; 
														 | 
														
														 | 
														
															 import { RootState } from '$app/stores/store'; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import { blockConfig } from '$app/constants/document/config'; 
														 | 
														
														 | 
														
															 import { blockConfig } from '$app/constants/document/config'; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import { Keyboard } from '$app/constants/document/keyboard'; 
														 | 
														
														 | 
														
															 import { Keyboard } from '$app/constants/document/keyboard'; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import { DOCUMENT_NAME, RANGE_NAME } from '$app/constants/document/name'; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+import { getPreviousWordIndex } from '$app/utils/document/delta'; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 /** 
														 | 
														
														 | 
														
															 /** 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * Delete a block by backspace or delete key 
														 | 
														
														 | 
														
															  * Delete a block by backspace or delete key 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -33,20 +35,25 @@ export const backspaceDeleteActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
														
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const state = (getState() as RootState).document[docId]; 
														 | 
														
														 | 
														
															     const state = (getState() as RootState).document[docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const node = state.nodes[id]; 
														 | 
														
														 | 
														
															     const node = state.nodes[id]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!node.parent) return; 
														 | 
														
														 | 
														
															     if (!node.parent) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const parent = state.nodes[node.parent]; 
														 | 
														
														 | 
														
															     const parent = state.nodes[node.parent]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const children = state.children[parent.children]; 
														 | 
														
														 | 
														
															     const children = state.children[parent.children]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const index = children.indexOf(id); 
														 | 
														
														 | 
														
															     const index = children.indexOf(id); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const nextNodeId = children[index + 1]; 
														 | 
														
														 | 
														
															     const nextNodeId = children[index + 1]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     // turn to text block 
														 | 
														
														 | 
														
															     // turn to text block 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (node.type !== BlockType.TextBlock) { 
														 | 
														
														 | 
														
															     if (node.type !== BlockType.TextBlock) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       await dispatch(turnToTextBlockThunk({ id, controller })); 
														 | 
														
														 | 
														
															       await dispatch(turnToTextBlockThunk({ id, controller })); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       return; 
														 | 
														
														 | 
														
															       return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const isTopLevel = parent.type === BlockType.PageBlock; 
														 | 
														
														 | 
														
															     const isTopLevel = parent.type === BlockType.PageBlock; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (isTopLevel || nextNodeId) { 
														 | 
														
														 | 
														
															     if (isTopLevel || nextNodeId) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       // merge to previous line 
														 | 
														
														 | 
														
															       // merge to previous line 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       const prevLine = findPrevHasDeltaNode(state, id); 
														 | 
														
														 | 
														
															       const prevLine = findPrevHasDeltaNode(state, id); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       if (!prevLine) return; 
														 | 
														
														 | 
														
															       if (!prevLine) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       const caretIndex = new Delta(prevLine.data.delta).length(); 
														 | 
														
														 | 
														
															       const caretIndex = new Delta(prevLine.data.delta).length(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       const caret = { 
														 | 
														
														 | 
														
															       const caret = { 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -54,6 +61,7 @@ export const backspaceDeleteActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         index: caretIndex, 
														 | 
														
														 | 
														
															         index: caretIndex, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         length: 0, 
														 | 
														
														 | 
														
															         length: 0, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }; 
														 | 
														
														 | 
														
															       }; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       await dispatch( 
														 | 
														
														 | 
														
															       await dispatch( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         mergeDeltaThunk({ 
														 | 
														
														 | 
														
															         mergeDeltaThunk({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           sourceId: id, 
														 | 
														
														 | 
														
															           sourceId: id, 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -70,6 +78,7 @@ export const backspaceDeleteActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       ); 
														 | 
														
														 | 
														
															       ); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       return; 
														 | 
														
														 | 
														
															       return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     // outdent 
														 | 
														
														 | 
														
															     // outdent 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     await dispatch(outdentNodeThunk({ id, controller })); 
														 | 
														
														 | 
														
															     await dispatch(outdentNodeThunk({ id, controller })); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   } 
														 | 
														
														 | 
														
															   } 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -88,21 +97,25 @@ export const enterActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { getState, dispatch } = thunkAPI; 
														 | 
														
														 | 
														
															     const { getState, dispatch } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const state = getState() as RootState; 
														 | 
														
														 | 
														
															     const state = getState() as RootState; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const docId = controller.documentId; 
														 | 
														
														 | 
														
															     const docId = controller.documentId; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const documentState = state.document[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const documentState = state[DOCUMENT_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
														
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const caret = state.documentRange[docId]?.caret; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const caret = state[RANGE_NAME][docId]?.caret; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!node || !caret || caret.id !== id) return; 
														 | 
														
														 | 
														
															     if (!node || !caret || caret.id !== id) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const delta = new Delta(node.data.delta); 
														 | 
														
														 | 
														
															     const delta = new Delta(node.data.delta); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (delta.length() === 0 && node.type !== BlockType.TextBlock) { 
														 | 
														
														 | 
														
															     if (delta.length() === 0 && node.type !== BlockType.TextBlock) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       // If the node is not a text block, turn it to a text block 
														 | 
														
														 | 
														
															       // If the node is not a text block, turn it to a text block 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       await dispatch(turnToTextBlockThunk({ id, controller })); 
														 | 
														
														 | 
														
															       await dispatch(turnToTextBlockThunk({ id, controller })); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       return; 
														 | 
														
														 | 
														
															       return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const nodeDelta = delta.slice(0, caret.index); 
														 | 
														
														 | 
														
															     const nodeDelta = delta.slice(0, caret.index); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const insertNodeDelta = new Delta(node.data.delta).slice(caret.index + caret.length); 
														 | 
														
														 | 
														
															     const insertNodeDelta = new Delta(node.data.delta).slice(caret.index + caret.length); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const insertNodeAction = getInsertEnterNodeAction(node, insertNodeDelta, controller); 
														 | 
														
														 | 
														
															     const insertNodeAction = getInsertEnterNodeAction(node, insertNodeDelta, controller); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!insertNodeAction) return; 
														 | 
														
														 | 
														
															     if (!insertNodeAction) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const updateNode = { 
														 | 
														
														 | 
														
															     const updateNode = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       ...node, 
														 | 
														
														 | 
														
															       ...node, 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -122,6 +135,7 @@ export const enterActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         ) 
														 | 
														
														 | 
														
															         ) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       : []; 
														 | 
														
														 | 
														
															       : []; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const actions = [insertNodeAction.action, controller.getUpdateAction(updateNode), ...moveChildrenAction]; 
														 | 
														
														 | 
														
															     const actions = [insertNodeAction.action, controller.getUpdateAction(updateNode), ...moveChildrenAction]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     await controller.applyActions(actions); 
														 | 
														
														 | 
														
															     await controller.applyActions(actions); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
														
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -142,6 +156,7 @@ export const tabActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   'document/tabActionForBlock', 
														 | 
														
														 | 
														
															   'document/tabActionForBlock', 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   async (payload: { id: string; controller: DocumentController }, thunkAPI) => { 
														 | 
														
														 | 
														
															   async (payload: { id: string; controller: DocumentController }, thunkAPI) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { dispatch } = thunkAPI; 
														 | 
														
														 | 
														
															     const { dispatch } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return dispatch(indentNodeThunk(payload)); 
														 | 
														
														 | 
														
															     return dispatch(indentNodeThunk(payload)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   } 
														 | 
														
														 | 
														
															   } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 ); 
														 | 
														
														 | 
														
															 ); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -152,10 +167,11 @@ export const upDownActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { docId, id, down } = payload; 
														 | 
														
														 | 
														
															     const { docId, id, down } = payload; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
														
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const state = getState() as RootState; 
														 | 
														
														 | 
														
															     const state = getState() as RootState; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const documentState = state.document[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const rangeState = state.documentRange[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const documentState = state[DOCUMENT_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const rangeState = state[RANGE_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const caret = rangeState.caret; 
														 | 
														
														 | 
														
															     const caret = rangeState.caret; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
														
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!node || !caret || id !== caret.id) return; 
														 | 
														
														 | 
														
															     if (!node || !caret || id !== caret.id) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     let newCaret; 
														 | 
														
														 | 
														
															     let newCaret; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -165,9 +181,11 @@ export const upDownActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else { 
														 | 
														
														 | 
														
															     } else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       newCaret = transformToPrevLineCaret(documentState, caret); 
														 | 
														
														 | 
														
															       newCaret = transformToPrevLineCaret(documentState, caret); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!newCaret) { 
														 | 
														
														 | 
														
															     if (!newCaret) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       return; 
														 | 
														
														 | 
														
															       return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
														
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch( 
														 | 
														
														 | 
														
															     dispatch( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       rangeActions.setCaret({ 
														 | 
														
														 | 
														
															       rangeActions.setCaret({ 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -184,12 +202,14 @@ export const leftActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { id, docId } = payload; 
														 | 
														
														 | 
														
															     const { id, docId } = payload; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
														
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const state = getState() as RootState; 
														 | 
														
														 | 
														
															     const state = getState() as RootState; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const documentState = state.document[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const rangeState = state.documentRange[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const documentState = state[DOCUMENT_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const rangeState = state[RANGE_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const caret = rangeState.caret; 
														 | 
														
														 | 
														
															     const caret = rangeState.caret; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
														
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!node || !caret || id !== caret.id) return; 
														 | 
														
														 | 
														
															     if (!node || !caret || id !== caret.id) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     let newCaret: RangeStatic; 
														 | 
														
														 | 
														
															     let newCaret: RangeStatic; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (caret.length > 0) { 
														 | 
														
														 | 
														
															     if (caret.length > 0) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       newCaret = { 
														 | 
														
														 | 
														
															       newCaret = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         id, 
														 | 
														
														 | 
														
															         id, 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -198,15 +218,20 @@ export const leftActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       }; 
														 | 
														
														 | 
														
															       }; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else { 
														 | 
														
														 | 
														
															     } else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       if (caret.index > 0) { 
														 | 
														
														 | 
														
															       if (caret.index > 0) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        const delta = new Delta(node.data.delta); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        const newIndex = getPreviousWordIndex(delta, caret.index); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         newCaret = { 
														 | 
														
														 | 
														
															         newCaret = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           id, 
														 | 
														
														 | 
														
															           id, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-          index: caret.index - 1, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          index: newIndex, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           length: 0, 
														 | 
														
														 | 
														
															           length: 0, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }; 
														 | 
														
														 | 
														
															         }; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       } else { 
														 | 
														
														 | 
														
															       } else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         const prevNode = findPrevHasDeltaNode(documentState, id); 
														 | 
														
														 | 
														
															         const prevNode = findPrevHasDeltaNode(documentState, id); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         if (!prevNode) return; 
														 | 
														
														 | 
														
															         if (!prevNode) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         const prevDelta = new Delta(prevNode.data.delta); 
														 | 
														
														 | 
														
															         const prevDelta = new Delta(prevNode.data.delta); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         newCaret = { 
														 | 
														
														 | 
														
															         newCaret = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           id: prevNode.id, 
														 | 
														
														 | 
														
															           id: prevNode.id, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           index: prevDelta.length(), 
														 | 
														
														 | 
														
															           index: prevDelta.length(), 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -218,6 +243,7 @@ export const leftActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!newCaret) { 
														 | 
														
														 | 
														
															     if (!newCaret) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       return; 
														 | 
														
														 | 
														
															       return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
														
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch( 
														 | 
														
														 | 
														
															     dispatch( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       rangeActions.setCaret({ 
														 | 
														
														 | 
														
															       rangeActions.setCaret({ 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -234,14 +260,16 @@ export const rightActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { id, docId } = payload; 
														 | 
														
														 | 
														
															     const { id, docId } = payload; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
														
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const state = getState() as RootState; 
														 | 
														
														 | 
														
															     const state = getState() as RootState; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const documentState = state.document[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const rangeState = state.documentRange[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const documentState = state[DOCUMENT_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const rangeState = state[RANGE_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const caret = rangeState.caret; 
														 | 
														
														 | 
														
															     const caret = rangeState.caret; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
														
														 | 
														
															     const node = documentState.nodes[id]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!node || !caret || id !== caret.id) return; 
														 | 
														
														 | 
														
															     if (!node || !caret || id !== caret.id) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     let newCaret: RangeStatic; 
														 | 
														
														 | 
														
															     let newCaret: RangeStatic; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const delta = new Delta(node.data.delta); 
														 | 
														
														 | 
														
															     const delta = new Delta(node.data.delta); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const deltaLength = delta.length(); 
														 | 
														
														 | 
														
															     const deltaLength = delta.length(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (caret.length > 0) { 
														 | 
														
														 | 
														
															     if (caret.length > 0) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       newCaret = { 
														 | 
														
														 | 
														
															       newCaret = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         id, 
														 | 
														
														 | 
														
															         id, 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -251,6 +279,7 @@ export const rightActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } else { 
														 | 
														
														 | 
														
															     } else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       if (caret.index < deltaLength) { 
														 | 
														
														 | 
														
															       if (caret.index < deltaLength) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         const newIndex = caret.index + caret.length + 1; 
														 | 
														
														 | 
														
															         const newIndex = caret.index + caret.length + 1; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         newCaret = { 
														 | 
														
														 | 
														
															         newCaret = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           id, 
														 | 
														
														 | 
														
															           id, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           index: newIndex > deltaLength ? deltaLength : newIndex, 
														 | 
														
														 | 
														
															           index: newIndex > deltaLength ? deltaLength : newIndex, 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -258,6 +287,7 @@ export const rightActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }; 
														 | 
														
														 | 
														
															         }; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       } else { 
														 | 
														
														 | 
														
															       } else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         const nextNode = findNextHasDeltaNode(documentState, id); 
														 | 
														
														 | 
														
															         const nextNode = findNextHasDeltaNode(documentState, id); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         if (!nextNode) return; 
														 | 
														
														 | 
														
															         if (!nextNode) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         newCaret = { 
														 | 
														
														 | 
														
															         newCaret = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															           id: nextNode.id, 
														 | 
														
														 | 
														
															           id: nextNode.id, 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -270,6 +300,7 @@ export const rightActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!newCaret) { 
														 | 
														
														 | 
														
															     if (!newCaret) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       return; 
														 | 
														
														 | 
														
															       return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
														
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch( 
														 | 
														
														 | 
														
															     dispatch( 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -285,6 +316,7 @@ export const shiftTabActionForBlockThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   'document/shiftTabActionForBlock', 
														 | 
														
														 | 
														
															   'document/shiftTabActionForBlock', 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   async (payload: { id: string; controller: DocumentController }, thunkAPI) => { 
														 | 
														
														 | 
														
															   async (payload: { id: string; controller: DocumentController }, thunkAPI) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { dispatch } = thunkAPI; 
														 | 
														
														 | 
														
															     const { dispatch } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return dispatch(outdentNodeThunk(payload)); 
														 | 
														
														 | 
														
															     return dispatch(outdentNodeThunk(payload)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   } 
														 | 
														
														 | 
														
															   } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 ); 
														 | 
														
														 | 
														
															 ); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -301,8 +333,8 @@ export const arrowActionForRangeThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
														
														 | 
														
															     const { dispatch, getState } = thunkAPI; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const { key, docId } = payload; 
														 | 
														
														 | 
														
															     const { key, docId } = payload; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const state = getState() as RootState; 
														 | 
														
														 | 
														
															     const state = getState() as RootState; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const documentState = state.document[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    const rangeState = state.documentRange[docId]; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const documentState = state[DOCUMENT_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    const rangeState = state[RANGE_NAME][docId]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     let caret; 
														 | 
														
														 | 
														
															     let caret; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const leftCaret = getLeftCaretByRange(rangeState); 
														 | 
														
														 | 
														
															     const leftCaret = getLeftCaretByRange(rangeState); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     const rightCaret = getRightCaretByRange(rangeState); 
														 | 
														
														 | 
														
															     const rightCaret = getRightCaretByRange(rangeState); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -323,6 +355,7 @@ export const arrowActionForRangeThunk = createAsyncThunk( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         caret = transformToNextLineCaret(documentState, rightCaret); 
														 | 
														
														 | 
														
															         caret = transformToNextLineCaret(documentState, rightCaret); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         break; 
														 | 
														
														 | 
														
															         break; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!caret) return; 
														 | 
														
														 | 
														
															     if (!caret) return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
														
														 | 
														
															     dispatch(rangeActions.initialState(docId)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     dispatch( 
														 | 
														
														 | 
														
															     dispatch( 
														 |