From 0fc6cc2680cf955c336dbe4f98d62471b28eee15 Mon Sep 17 00:00:00 2001 From: celine Date: Fri, 16 Jan 2026 17:37:59 -0500 Subject: [PATCH] group multiselect delete into one undo group --- components/Toolbar/MultiSelectToolbar.tsx | 3 ++- src/utils/deleteBlock.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/Toolbar/MultiSelectToolbar.tsx b/components/Toolbar/MultiSelectToolbar.tsx index ef2aa833..654902c1 100644 --- a/components/Toolbar/MultiSelectToolbar.tsx +++ b/components/Toolbar/MultiSelectToolbar.tsx @@ -13,7 +13,7 @@ import { Separator, ShortcutKey } from "components/Layout"; export const MultiselectToolbar = (props: { setToolbarState: (state: "multiselect" | "text-alignment") => void; }) => { - const { rep } = useReplicache(); + const { rep, undoManager } = useReplicache(); const smoker = useSmoker(); const toaster = useToaster(); @@ -39,6 +39,7 @@ export const MultiselectToolbar = (props: { await deleteBlock( sortedSelection.map((b) => b.value), rep, + undoManager, ); toaster({ diff --git a/src/utils/deleteBlock.ts b/src/utils/deleteBlock.ts index 50eb3b32..bc35e9f6 100644 --- a/src/utils/deleteBlock.ts +++ b/src/utils/deleteBlock.ts @@ -4,10 +4,12 @@ import { useUIState } from "src/useUIState"; import { scanIndex } from "src/replicache/utils"; import { getBlocksWithType } from "src/hooks/queries/useBlocks"; import { focusBlock } from "src/utils/focusBlock"; +import { UndoManager } from "src/undoManager"; export async function deleteBlock( entities: string[], rep: Replicache, + undoManager?: UndoManager, ) { // get what pagess we need to close as a result of deleting this block let pagesToClose = [] as string[]; @@ -32,8 +34,7 @@ export async function deleteBlock( } } - // the next and previous blocks in the block list - // if the focused thing is a page and not a block, return + // figure out what to focus let focusedBlock = useUIState.getState().focusedEntity; let parent = focusedBlock?.entityType === "page" @@ -44,12 +45,14 @@ export async function deleteBlock( let parentType = await rep?.query((tx) => scanIndex(tx).eav(parent, "page/type"), ); + // if the page is a canvas, focus the page if (parentType[0]?.data.value === "canvas") { useUIState .getState() .setFocusedBlock({ entityType: "page", entityID: parent }); useUIState.getState().setSelectedBlocks([]); } else { + // if the page is a doc, focus the previous block (or if there isn't a prev block, focus the next block) let siblings = (await rep?.query((tx) => getBlocksWithType(tx, parent))) || []; @@ -105,7 +108,11 @@ export async function deleteBlock( } } + // close the pages pagesToClose.forEach((page) => page && useUIState.getState().closePage(page)); + undoManager && undoManager.startGroup(); + + // delete the blocks await Promise.all( entities.map((entity) => rep?.mutate.removeBlock({ @@ -113,4 +120,5 @@ export async function deleteBlock( }), ), ); + undoManager && undoManager.endGroup(); } -- 2.51.2