a tool for shared writing and social publishing

group multiselect delete into one undo group

+12 -3
+2 -1
components/Toolbar/MultiSelectToolbar.tsx
··· 13 13 export const MultiselectToolbar = (props: { 14 14 setToolbarState: (state: "multiselect" | "text-alignment") => void; 15 15 }) => { 16 - const { rep } = useReplicache(); 16 + const { rep, undoManager } = useReplicache(); 17 17 const smoker = useSmoker(); 18 18 const toaster = useToaster(); 19 19 ··· 39 39 await deleteBlock( 40 40 sortedSelection.map((b) => b.value), 41 41 rep, 42 + undoManager, 42 43 ); 43 44 44 45 toaster({
+10 -2
src/utils/deleteBlock.ts
··· 4 4 import { scanIndex } from "src/replicache/utils"; 5 5 import { getBlocksWithType } from "src/hooks/queries/useBlocks"; 6 6 import { focusBlock } from "src/utils/focusBlock"; 7 + import { UndoManager } from "src/undoManager"; 7 8 8 9 export async function deleteBlock( 9 10 entities: string[], 10 11 rep: Replicache<ReplicacheMutators>, 12 + undoManager?: UndoManager, 11 13 ) { 12 14 // get what pagess we need to close as a result of deleting this block 13 15 let pagesToClose = [] as string[]; ··· 32 34 } 33 35 } 34 36 35 - // the next and previous blocks in the block list 36 - // if the focused thing is a page and not a block, return 37 + // figure out what to focus 37 38 let focusedBlock = useUIState.getState().focusedEntity; 38 39 let parent = 39 40 focusedBlock?.entityType === "page" ··· 44 45 let parentType = await rep?.query((tx) => 45 46 scanIndex(tx).eav(parent, "page/type"), 46 47 ); 48 + // if the page is a canvas, focus the page 47 49 if (parentType[0]?.data.value === "canvas") { 48 50 useUIState 49 51 .getState() 50 52 .setFocusedBlock({ entityType: "page", entityID: parent }); 51 53 useUIState.getState().setSelectedBlocks([]); 52 54 } else { 55 + // if the page is a doc, focus the previous block (or if there isn't a prev block, focus the next block) 53 56 let siblings = 54 57 (await rep?.query((tx) => getBlocksWithType(tx, parent))) || []; 55 58 ··· 105 108 } 106 109 } 107 110 111 + // close the pages 108 112 pagesToClose.forEach((page) => page && useUIState.getState().closePage(page)); 113 + undoManager && undoManager.startGroup(); 114 + 115 + // delete the blocks 109 116 await Promise.all( 110 117 entities.map((entity) => 111 118 rep?.mutate.removeBlock({ ··· 113 120 }), 114 121 ), 115 122 ); 123 + undoManager && undoManager.endGroup(); 116 124 }