diff --git a/components/Blocks/ButtonBlock.tsx b/components/Blocks/ButtonBlock.tsx index af08221d..f7e0604d 100644 --- a/components/Blocks/ButtonBlock.tsx +++ b/components/Blocks/ButtonBlock.tsx @@ -24,12 +24,12 @@ export const ButtonBlock = (props: BlockProps & { preview?: boolean }) => { let isSelected = useUIState((s) => s.selectedBlocks.find((b) => b.value === props.entityID), ); + let alignment = useEntity(props.entityID, "block/text-alignment")?.data.value; if (!url) { if (!permissions.write) return null; return ; } - let alignment = useEntity(props.entityID, "block/text-alignment")?.data.value; return ( ) => { - let selection = window.getSelection(); - if (!selection || selection.rangeCount === 0) return; - let range = selection.getRangeAt(0); - if (!range) return; - let length = range.toString().length; - range.setStart(e.currentTarget, 0); - let end = range.toString().length; - let start = end - length; - - flushSync(() => { - useUIState.getState().setSelectedBlock(props); - useUIState.getState().setFocusedBlock({ - entityType: "block", - entityID: props.value, - parent: props.parent, - }); - }); - let el = document.getElementById( - elementId.block(props.entityID).input, - ) as HTMLTextAreaElement; - if (!el) return; - el.focus(); - el.setSelectionRange(start, end); + focusBlock( + { parent: props.parent, value: props.value, type: "code" }, + { type: "end" }, + ); }, []); return ( @@ -120,11 +102,11 @@ export function CodeBlock(props: BlockProps) { )} {permissions.write && ( - - + + Theme:{" "} { e.preventDefault(); e.stopPropagation(); @@ -146,7 +128,7 @@ export function CodeBlock(props: BlockProps) { { e.preventDefault(); e.stopPropagation(); diff --git a/src/utils/focusBlock.ts b/src/utils/focusBlock.ts index fcf23cc2..f0e0ad2c 100644 --- a/src/utils/focusBlock.ts +++ b/src/utils/focusBlock.ts @@ -48,7 +48,9 @@ export function focusBlock( } if (pos?.offset !== undefined) { - el?.focus(); + // trying to focus the block in a subpage causes the page to flash and scroll back to the parent page. + // idk how to fix so i'm giving up -- celine + // el?.focus(); requestAnimationFrame(() => { el?.setSelectionRange(pos.offset, pos.offset); });