@@ -109,6 +109,9 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
109109 ...state ,
110110 content : { ...state . content , blocks : newBlocksConfig } ,
111111 } ) ) ;
112+
113+ // Set the inserted block as selected
114+ get ( ) . setSelectedBlock ( arrayPath ) ;
112115 } ,
113116 enableInsertMode ( blockType : string ) {
114117 set ( ( state ) => ( {
@@ -180,6 +183,9 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
180183 } ) ) ;
181184 } ,
182185 reorderBlock : ( arrayPath , destination , position = 'append' ) => {
186+ // Create a copy of the destination array before any modifications
187+ let finalDestinationPath : number [ ] = _ . cloneDeep ( destination ) ;
188+
183189 if ( position === 'append' ) {
184190 // TODO: fix
185191 // 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>(
199205 destination [ destination . length - 1 ] ,
200206 ) ;
201207 } ) ;
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+ }
202216 } else {
203217 const arrayDest = getDestinationShiftBeforeReorder ( arrayPath , destination ) ;
218+ finalDestinationPath = _ . cloneDeep ( arrayDest ) ;
204219
205220 // Delete
206221 const blocksConfigWithoutBlock = modifyObjectByPath (
@@ -220,6 +235,8 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
220235 ...state ,
221236 content : { ...state . content , blocks : newBlocksConfig } ,
222237 } ) ) ;
238+
239+ get ( ) . setSelectedBlock ( finalDestinationPath ) ;
223240 } ,
224241 resetInitialize : ( ) => {
225242 set ( ( state ) => ( {
0 commit comments