commit 223ee275a1aaf9f695a79e6552a8a8b5c1f9770f
parent 713814b3ce2e13431a2529f47aee570dcb9a5df1
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 10 Nov 2026 16:09:19 -0500
umtool: an open block menu follows its block when the strip is read again under it (an undo landing, another writer) -- by its one block with that id; it closes only when the block left or its id is now on two blocks. block-menus.spec waits for the undo to land before asking c04's menu (the gate's run right-clicked c04 in the old view, place 4, which became c03's)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/umtool/components/projects/workspace/BlockStrip.tsx b/umtool/components/projects/workspace/BlockStrip.tsx
@@ -81,7 +81,8 @@ export default function BlockStrip({
const [over, setOver] = useState<string | null>(null);
// The open menu: its block -- by its place in the strip, two blocks may share an id -- and where it opens. A ref
// too, so the key's menu and the contextmenu event the browser may send after it open one menu.
- const [open, setOpen] = useState<{ id: string; i: number; anchor: MenuAnchor } | null>(null);
+ const [open, setOpen] = useState<{ id: string; i: number; anchor: MenuAnchor; seq: number } | null>(null);
+ const seq = useRef(0);
const openRef = useRef<{ id: string; i: number } | null>(null);
const blockEl = (i: number) => ref.current?.querySelector(`[data-ws-block-i="${i}"]`) as HTMLElement | null;
const showMenu = (id: string, i: number, anchor: MenuAnchor | null) => {
@@ -89,7 +90,8 @@ export default function BlockStrip({
const r = blockEl(i)?.getBoundingClientRect();
const at: MenuAnchor = anchor ?? { rect: { left: r?.left ?? 8, top: r?.top ?? 8, bottom: r?.bottom ?? 8 } };
openRef.current = { id, i };
- setOpen({ id, i, anchor: at });
+ seq.current += 1;
+ setOpen({ id, i, anchor: at, seq: seq.current });
};
const closeMenu = useCallback((refocus: boolean) => {
const o = openRef.current;
@@ -97,12 +99,23 @@ export default function BlockStrip({
setOpen(null);
if (refocus && o) (ref.current?.querySelector(`[data-ws-block-i="${o.i}"]`) as HTMLElement | null)?.focus();
}, []);
- const found = open && menu ? menu.info(open.i) : null;
+ // Where its block is now: its place, or -- the strip re-read under it (an undo landing, another writer) -- the
+ // one block with its id. A block that left, or whose id is now on two blocks, takes the menu with it.
+ const openAt = (() => {
+ if (!open) return null;
+ if (blocks[open.i]?.id === open.id) return open.i;
+ const hits = blocks.flatMap((b, j) => (b.id === open.id ? [j] : []));
+ return hits.length === 1 ? hits[0] : null;
+ })();
+ const found = openAt !== null && menu ? menu.info(openAt) : null;
const openInfo = found && found.id === open?.id ? found : null;
- // Its block left the cut, or moved from under it (an undo, another writer): the menu goes with it.
useEffect(() => {
if (open && !openInfo) closeMenu(false);
- }, [open, openInfo, closeMenu]);
+ else if (open && openAt !== null && openAt !== open.i) {
+ openRef.current = { id: open.id, i: openAt };
+ setOpen({ ...open, i: openAt });
+ }
+ }, [open, openInfo, openAt, closeMenu]);
// The selected block kept in view (the keys walk past the strip's edge).
useEffect(() => {
if (!selected) return;
@@ -233,7 +246,7 @@ export default function BlockStrip({
<div className="flex shrink-0 items-stretch" data-ws-plus-slot="">
{plus}
</div>
- {open && openInfo && menu && <BlockMenu key={`${open.id}@${open.i}`} place={open.i} info={openInfo} actions={menu} anchor={open.anchor} onClose={closeMenu} />}
+ {open && openInfo && menu && <BlockMenu key={open.seq} place={openAt ?? open.i} info={openInfo} actions={menu} anchor={open.anchor} onClose={closeMenu} />}
</div>
);
}
diff --git a/umtool/e2e/block-menus.spec.ts b/umtool/e2e/block-menus.spec.ts
@@ -246,6 +246,8 @@ test("a variant twin: Remove takes the entry on screen, never its twin; a twin t
await expect(page.locator("[data-ws-undo-said]")).toContainText("Removed c03");
await page.locator("[data-ws-undo]").click();
await expect.poll(manifestText, { timeout: 15_000 }).toBe(written);
+ // The strip has read the undo back (c03 is on it again) before c04's menu is asked for.
+ await expect(block(page, "c03")).toBeVisible();
// c04: no place of its own, its id twice -- never guessed at.
await block(page, "c04").click({ button: "right" });