From 70991ca010d6ce0912accd3ee04940b4173a2031 Mon Sep 17 00:00:00 2001 From: celine Date: Wed, 21 Jan 2026 17:59:22 -0500 Subject: [PATCH] small block bugs --- components/Blocks/ButtonBlock.tsx | 2 +- components/Blocks/CodeBlock.tsx | 36 ++++++++----------------------- src/utils/focusBlock.ts | 4 +++- 3 files changed, 13 insertions(+), 29 deletions(-) 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:{" "}