@@ -109,6 +109,9 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
109
109
...state ,
110
110
content : { ...state . content , blocks : newBlocksConfig } ,
111
111
} ) ) ;
112
+
113
+ // Set the inserted block as selected
114
+ get ( ) . setSelectedBlock ( arrayPath ) ;
112
115
} ,
113
116
enableInsertMode ( blockType : string ) {
114
117
set ( ( state ) => ( {
@@ -180,6 +183,9 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
180
183
} ) ) ;
181
184
} ,
182
185
reorderBlock : ( arrayPath , destination , position = 'append' ) => {
186
+ // Create a copy of the destination array before any modifications
187
+ let finalDestinationPath : number [ ] = _ . cloneDeep ( destination ) ;
188
+
183
189
if ( position === 'append' ) {
184
190
// TODO: fix
185
191
// eslint-disable-next-line no-not-accumulator-reassign/no-not-accumulator-reassign, no-param-reassign
@@ -199,8 +205,17 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
199
205
destination [ destination . length - 1 ] ,
200
206
) ;
201
207
} ) ;
208
+
209
+ if (
210
+ position === 'append' &&
211
+ destination [ destination . length - 1 ] < arrayPath [ arrayPath . length - 1 ]
212
+ ) {
213
+ finalDestinationPath [ finalDestinationPath . length - 1 ] =
214
+ finalDestinationPath [ finalDestinationPath . length - 1 ] + 1 ;
215
+ }
202
216
} else {
203
217
const arrayDest = getDestinationShiftBeforeReorder ( arrayPath , destination ) ;
218
+ finalDestinationPath = _ . cloneDeep ( arrayDest ) ;
204
219
205
220
// Delete
206
221
const blocksConfigWithoutBlock = modifyObjectByPath (
@@ -220,6 +235,8 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
220
235
...state ,
221
236
content : { ...state . content , blocks : newBlocksConfig } ,
222
237
} ) ) ;
238
+
239
+ get ( ) . setSelectedBlock ( finalDestinationPath ) ;
223
240
} ,
224
241
resetInitialize : ( ) => {
225
242
set ( ( state ) => ( {
0 commit comments