From 6c8a991cb6ed1a96137433e8c543e9afc8356b45 Mon Sep 17 00:00:00 2001 From: celine Date: Wed, 14 Jan 2026 17:56:16 -0500 Subject: [PATCH] reverted the last change and redid it in a not stupid way --- components/Blocks/Block.tsx | 3 --- components/Blocks/useBlockMouseHandlers.ts | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/Blocks/Block.tsx b/components/Blocks/Block.tsx index 1f7ca9bb..64efceec 100644 --- a/components/Blocks/Block.tsx +++ b/components/Blocks/Block.tsx @@ -88,9 +88,6 @@ export const Block = memo(function Block( let [areYouSure, setAreYouSure] = useState(false); useEffect(() => { - if (selected && rep) { - focusPage(props.parent, rep); - } if (!selected) { setAreYouSure(false); } diff --git a/components/Blocks/useBlockMouseHandlers.ts b/components/Blocks/useBlockMouseHandlers.ts index fd1e0188..eca3cc68 100644 --- a/components/Blocks/useBlockMouseHandlers.ts +++ b/components/Blocks/useBlockMouseHandlers.ts @@ -8,6 +8,8 @@ import { useReplicache } from "src/replicache"; import { getBlocksWithType } from "src/hooks/queries/useBlocks"; import { focusBlock } from "src/utils/focusBlock"; import { useIsMobile } from "src/hooks/isMobile"; +import { scrollIntoViewIfNeeded } from "src/utils/scrollIntoViewIfNeeded"; +import { elementId } from "src/utils/elementId"; let debounce: number | null = null; export function useBlockMouseHandlers(props: Block) { @@ -39,6 +41,16 @@ export function useBlockMouseHandlers(props: Block) { parent: props.parent, }); useUIState.getState().setSelectedBlock(props); + + // scroll to the page containing the block, if offscreen + let parentPage = elementId.page(props.parent).container; + setTimeout(() => { + scrollIntoViewIfNeeded( + document.getElementById(parentPage), + false, + "smooth", + ); + }, 50); } }, [props, entity_set.permissions.write, isMobile], -- 2.51.2