Skip to content

Commit 2d44b85

Browse files
committed
feat: unselect block on deletion
1 parent 879cfb7 commit 2d44b85

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

common/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface EditorState {
1111
zoom: number;
1212

1313
manipulateOverlayMode: 'insert' | 'reorder' | false;
14-
selectedBlock?: number[];
14+
selectedBlock: number[] | null;
1515
initialized: boolean;
1616

1717
content: PageContentWithNavigation;
@@ -28,7 +28,7 @@ export const initialStore: EditorState = {
2828
deviceWidth: '100%',
2929
zoom: 100,
3030
manipulateOverlayMode: false,
31-
selectedBlock: undefined,
31+
selectedBlock: null,
3232
initialized: false,
3333
content: {blocks: []},
3434
blocks: [],

editor-v2/store.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919

2020
export interface EditorMethods {
2121
initialize(): void;
22-
setSelectedBlock(path?: number[]): void;
22+
setSelectedBlock(path: number[] | null): void;
2323
setHeight(height: number): void;
2424
setDeviceWidth(deviceWidth: string): void;
2525
setZoom(zoom: number): void;
@@ -108,10 +108,8 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
108108
set((state) => ({
109109
...state,
110110
content: {...state.content, blocks: newBlocksConfig},
111+
selectedBlock: arrayPath,
111112
}));
112-
113-
// Set the inserted block as selected
114-
get().setSelectedBlock(arrayPath);
115113
},
116114
enableInsertMode(blockType: string) {
117115
set((state) => ({
@@ -166,10 +164,10 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
166164
const blocksConfig = get().content.blocks;
167165

168166
const newBlocksConfig = modifyObjectByPath(blocksConfig, arrayPath, removeFromArray);
169-
170167
set((state) => ({
171168
...state,
172169
content: {...state.content, blocks: newBlocksConfig},
170+
selectedBlock: null,
173171
}));
174172
},
175173
duplicateBlock: (arrayPath) => {
@@ -234,9 +232,8 @@ export const createEditorStore = initializeStore<EditorState, EditorMethods>(
234232
set((state) => ({
235233
...state,
236234
content: {...state.content, blocks: newBlocksConfig},
235+
selectedBlock: finalDestinationPath,
237236
}));
238-
239-
get().setSelectedBlock(finalDestinationPath);
240237
},
241238
resetInitialize: () => {
242239
set((state) => ({

src/hooks/usePCEditorBlockSelection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const usePCEditorBlockSelection = (arrayIndex: number[], element?: HTMLElement)
1414
sendEventPostMessage('ON_UPDATE_BLOCK_SELECTION', {rect});
1515
}
1616
}
17-
}, [JSON.stringify(arrayIndex), element, JSON.stringify(selectedBlock)]);
17+
}, [arrayIndex, element, selectedBlock]);
1818

1919
React.useEffect(() => {
2020
window.addEventListener('resize', onResize);
@@ -24,6 +24,7 @@ const usePCEditorBlockSelection = (arrayIndex: number[], element?: HTMLElement)
2424
};
2525
}, [element, onResize]);
2626

27+
// Update blockBorders when selectedBlock changes
2728
React.useEffect(() => {
2829
onResize();
2930
}, [onResize]);

0 commit comments

Comments
 (0)