GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • apps/web/src
    • components
      • ThreadTerminalDrawer.tsx
    • contextMenuFallback.test.ts
    • contextMenuFallback.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ThreadTerminalDrawer.tsx
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,11 @@ export function TerminalViewport({
685685
}
686686
clearSelectionAction();
687687
// 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+
}
690693
}
691694

692695
const handleMouseUp = (event: MouseEvent) => {
Collapse file

‎apps/web/src/contextMenuFallback.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/contextMenuFallback.test.ts
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,18 @@ describe("dismissContextMenu", () => {
255255
dismissContextMenu();
256256
expect(findButton("Rename")).toBeUndefined();
257257
});
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+
});
258272
});
Collapse file

‎apps/web/src/contextMenuFallback.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/contextMenuFallback.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ export function showContextMenuFallback<T extends string>(
319319
document.addEventListener("pointerdown", onPointerDown, true);
320320
document.addEventListener("contextmenu", onContextMenu, true);
321321
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+
}
322328
activeContextMenuDismiss = dismiss;
323329

324330
requestAnimationFrame(() => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.