GeezerVison is showing github.com — fix(web): keep terminal menu close scoped to its own menu · pingdotgg/t3code@e8d7ab1
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/components/ThreadTerminalDrawer.tsx +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -685,8 +685,11 @@ export function TerminalViewport({ |
685 | 685 | } |
686 | 686 | clearSelectionAction(); |
687 | 687 | // A copy shortcut that clears the selection (Ctrl+C) must also close |
688 | | - // the context menu that appears with the selection. |
689 | | - void localApi?.contextMenu.close(); |
| 688 | + // the context menu that appears with the selection, but a clear that |
| 689 | + // never opened a menu must not dismiss an unrelated one. |
| 690 | + if (selectionActionMenuOpenRef.current) { |
| 691 | + void localApi?.contextMenu.close(); |
| 692 | + } |
690 | 693 | } |
691 | 694 |
|
692 | 695 | const handleMouseUp = (event: MouseEvent) => { |
|
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/contextMenuFallback.test.ts +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -255,4 +255,18 @@ describe("dismissContextMenu", () => { |
255 | 255 | dismissContextMenu(); |
256 | 256 | expect(findButton("Rename")).toBeUndefined(); |
257 | 257 | }); |
| 258 | + |
| 259 | + it("dismisses the prior menu when a new one opens", async () => { |
| 260 | + const firstPromise = showContextMenuFallback([{ id: "first", label: "First" }]); |
| 261 | + expect(findButton("First")).toBeTruthy(); |
| 262 | + |
| 263 | + const secondPromise = showContextMenuFallback([{ id: "second", label: "Second" }]); |
| 264 | + |
| 265 | + await expect(firstPromise).resolves.toBeNull(); |
| 266 | + expect(findButton("First")).toBeUndefined(); |
| 267 | + expect(findButton("Second")).toBeTruthy(); |
| 268 | + |
| 269 | + dismissContextMenu(); |
| 270 | + await expect(secondPromise).resolves.toBeNull(); |
| 271 | + }); |
258 | 272 | }); |
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/contextMenuFallback.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -319,6 +319,12 @@ export function showContextMenuFallback<T extends string>( |
319 | 319 | document.addEventListener("pointerdown", onPointerDown, true); |
320 | 320 | document.addEventListener("contextmenu", onContextMenu, true); |
321 | 321 | openMenu(items, position?.x ?? 0, position?.y ?? 0, 0); |
| 322 | + // Only one fallback menu can be open at a time: a new show must dismiss |
| 323 | + // any prior one, or its DOM and listeners leak and close() can only ever |
| 324 | + // reach the newest menu. |
| 325 | + if (activeContextMenuDismiss) { |
| 326 | + activeContextMenuDismiss(); |
| 327 | + } |
322 | 328 | activeContextMenuDismiss = dismiss; |
323 | 329 |
|
324 | 330 | requestAnimationFrame(() => { |
|