fix(web): make terminal selection actions reliable #6555
ClosedAdamulek123(GitHub profile, opens in a new tab)wants to merge 13 commits into
main fromrefs/pull/6555/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/terminal/ghostty/surface.ts line 964Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -845,3 +846,4 @@845846 this.requestRender();846847 }847848849+ paste(data: string): void {
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/web/src/components/ThreadTerminalDrawer.tsx line 661OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -571,0 +641,21 @@641+ const requestId = ++selectionActionRequestIdRef.current;642+ terminalMenuAbortController?.abort();643+ const abortController = new AbortController();644+ terminalMenuAbortController = abortController;645+ selectionActionMenuOpenRef.current = true;646+ const clicked = await localApi.contextMenu647+ .show(648+ terminalContextMenuItems({649+ canAddToChat: selectionAction?.selection != null,650+ canCopy: selectionAction !== null,651+ }),652+ {653+ x: event.clientX,654+ y: event.clientY,655+ },656+ { presentation: "styled", signal: abortController.signal },657+ )658+ .finally(() => {659+ if (terminalMenuAbortController === abortController) {660+ terminalMenuAbortController = null;661+ selectionActionMenuOpenRef.current = false;apps/web/src/contextMenuFallback.ts line 288OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -167,12 +217,16 @@217+ const usesCompactShortcutLayout = entries.some((item) => item.accelerator);167218 const menu = document.createElement("div");168- menu.className =169- "dropdown-glass fixed z-[10000] min-w-32 max-w-sm overflow-hidden rounded-lg bg-clip-padding text-popover-foreground outline-none";170- menu.style.cssText =171- "position:fixed;z-index:10000;min-width:8rem;max-width:24rem;overflow:hidden;border-radius:var(--radius-lg);background-clip:padding-box;color:var(--popover-foreground);outline:none;pointer-events:auto;";219+ menu.className = `dropdown-glass fixed z-[10000] max-w-sm overflow-hidden bg-clip-padding text-popover-foreground outline-none ${220+ usesCompactShortcutLayout ? "min-w-[14.25rem] rounded-[11px]" : "min-w-32 rounded-lg"221+ }`;222+ menu.style.cssText = `position:fixed;z-index:10000;min-width:${223+ usesCompactShortcutLayout ? "min(14.25rem,calc(100vw - 0.75rem))" : "8rem"224+ };max-width:24rem;overflow:hidden;border-radius:${225+ usesCompactShortcutLayout ? "0.6875rem" : "var(--radius-lg)"226+ };background-clip:padding-box;color:var(--popover-foreground);outline:none;pointer-events:auto;`;172227 menu.style.left = `${preferredLeft}px`;173228 menu.style.top = `${preferredTop}px`;174229 menu.dataset.level = String(level);175230176231 const inner = document.createElement("div");177232 inner.className =178- "max-h-[min(24rem,70vh)] min-w-0 max-w-sm overflow-y-auto overflow-x-hidden p-1";
- apps/web/src/contextMenuFallback.ts lines 377 to 383OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -315,7 +374,10 @@315374 button.type = "button";316375 const isDisabled = item.disabled === true;317376 button.disabled = isDisabled;318- const rowBase =319- "flex w-full cursor-default select-none items-center gap-2 rounded-sm px-2 py-1 text-left outline-none transition-colors sm:min-h-7 sm:text-sm min-h-8 text-base";377+ const rowBase = usesCompactShortcutLayout378+ ? "flex min-h-[2.125rem] w-full cursor-default select-none items-center gap-[9px] rounded-[7px] px-2 py-1.5 text-left text-xs outline-none transition-colors"379+ : "flex w-full cursor-default select-none items-center gap-2 rounded-sm px-2 py-1 text-left outline-none transition-colors sm:min-h-7 sm:text-sm min-h-8 text-base";320380 button.className = isDisabled321- ? `${rowBase} pointer-events-none cursor-not-allowed text-muted-foreground opacity-64`381+ ? `${rowBase} pointer-events-none cursor-not-allowed text-muted-foreground ${382+ usesCompactShortcutLayout ? "opacity-52" : "opacity-64"383+ }`apps/web/src/contextMenuFallback.ts lines 329 to 338OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -274,8 +326,13 @@274326 ) => {275327 closeMenusFromLevel(level);276328329+ const usesCompactShortcutLayout = entries.some((item) => item.accelerator);277330 const menu = document.createElement("div");278- menu.className =279- "dropdown-glass fixed z-[10000] min-w-32 max-w-sm overflow-hidden rounded-lg bg-clip-padding text-popover-foreground outline-none";280- menu.style.cssText =281- "position:fixed;z-index:10000;min-width:8rem;max-width:24rem;overflow:hidden;border-radius:var(--radius-lg);background-clip:padding-box;color:var(--popover-foreground);outline:none;pointer-events:auto;";331+ menu.className = `dropdown-glass fixed z-[10000] max-w-sm overflow-hidden bg-clip-padding text-popover-foreground outline-none ${332+ usesCompactShortcutLayout ? "min-w-[14.25rem] rounded-[11px]" : "min-w-32 rounded-lg"333+ }`;334+ menu.style.cssText = `position:fixed;z-index:10000;min-width:${335+ usesCompactShortcutLayout ? "min(14.25rem,calc(100vw - 0.75rem))" : "8rem"336+ };max-width:24rem;overflow:hidden;border-radius:${337+ usesCompactShortcutLayout ? "0.6875rem" : "var(--radius-lg)"338+ };background-clip:padding-box;color:var(--popover-foreground);outline:none;pointer-events:auto;`;apps/web/src/components/ThreadTerminalDrawer.tsx lines 855 to 858Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -786,3 +800,7 @@786800 })();787801 }788802803+ function handleContextMenu(event: MouseEvent): void {804+ clearSelectionAction();805+ void showTerminalContextMenu(event);806+ }apps/web/src/contextMenuFallback.ts lines 423 to 431Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -345,3 +414,12 @@345414 label.textContent = item.label;346415 button.appendChild(label);347416417+ if (item.accelerator) {418+ const accelerator = document.createElement("kbd");419+ accelerator.className =420+ "ms-auto shrink-0 rounded border border-border/70 bg-muted/70 px-[5px] font-mono text-[10px] text-muted-foreground leading-[1.55]";421+ accelerator.style.cssText =422+ "margin-inline-start:auto;flex-shrink:0;border:1px solid color-mix(in srgb,var(--border) 70%,transparent);border-radius:0.25rem;background:color-mix(in srgb,var(--muted) 70%,transparent);padding:0 0.3125rem;color:var(--muted-foreground);font-family:var(--font-mono,monospace);font-size:0.625rem;line-height:1.55;";423+ accelerator.textContent = item.accelerator.replace(/^Command\+/u, "⌘");424+ button.appendChild(accelerator);425+ }
- apps/web/src/contextMenuFallback.ts line 276Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -223,6 +256,8 @@223256 if (activeContextMenuDismiss === dismiss) {224257 activeContextMenuDismiss = null;225258 }226- document.removeEventListener("keydown", onKeyDown);259+ document.removeEventListener("keydown", onKeyDown, true);227260 document.removeEventListener("pointerdown", onPointerDown, true);228261 document.removeEventListener("contextmenu", onContextMenu, true);262+ document.removeEventListener("wheel", onWheel, true);263+ options?.signal?.removeEventListener("abort", onAbort);apps/web/src/components/ThreadTerminalDrawer.tsx line 858Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -786,3 +800,7 @@786800 })();787801 }788802803+ function handleContextMenu(event: MouseEvent): void {804+ clearSelectionAction();805+ void showTerminalContextMenu(event);806+ }
- apps/web/src/components/ThreadTerminalDrawer.tsx line 647OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -672,5 +639,9 @@672639 return;673640 }674641 const requestId = ++selectionActionRequestIdRef.current;642+ terminalMenuAbortController?.abort();643+ const abortController = new AbortController();644+ terminalMenuAbortController = abortController;645+ selectionActionMenuOpenRef.current = true;675646 openSelectionMenuRequestIdRef.current = requestId;676647 const clicked = await localApi.contextMenu
- apps/web/src/terminal/ghostty/surface.ts lines 1515 to 1515Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1508,3 +1512,4 @@15081512 };1509151315101514 private readonly onContextMenu = (event: MouseEvent) => {1515+ event.preventDefault();apps/web/src/contextMenuFallback.ts lines 357 to 357Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -274,11 +343,14 @@274343 ) => {275344 closeMenusFromLevel(level);276345346+ const usesCompactShortcutLayout = options?.layout === "compact";277347 const menu = document.createElement("div");278- menu.className =279- "dropdown-glass fixed z-[10000] min-w-32 max-w-sm overflow-hidden rounded-lg bg-clip-padding text-popover-foreground outline-none";280- menu.style.cssText =281- "position:fixed;z-index:10000;min-width:8rem;max-width:24rem;overflow:hidden;border-radius:var(--radius-lg);background-clip:padding-box;color:var(--contrast-popover-foreground);outline:none;pointer-events:auto;";348+ menu.className = `dropdown-glass fixed z-[10000] max-w-sm overflow-hidden bg-clip-padding text-popover-foreground outline-none ${349+ usesCompactShortcutLayout ? "min-w-56 rounded-lg" : "min-w-32 rounded-lg"350+ }`;351+ menu.style.cssText = `position:fixed;z-index:10000;min-width:${352+ usesCompactShortcutLayout ? "min(14rem,calc(100vw - 0.75rem))" : "8rem"353+ };max-width:24rem;overflow:hidden;border-radius:var(--radius-lg);background-clip:padding-box;color:var(--contrast-popover-foreground);outline:none;pointer-events:auto;`;282354 menu.style.left = `${preferredLeft}px`;283355 menu.style.top = `${preferredTop}px`;284356 menu.dataset.level = String(level);apps/web/src/contextMenuFallback.ts lines 422 to 423Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -346,3 +420,4 @@346420 label.textContent = item.label;347421 button.appendChild(label);348422423+ if (item.accelerator) {
- apps/web/src/contextMenuFallback.ts line 428OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -346,3 +420,9 @@346420 label.textContent = item.label;347421 button.appendChild(label);348422423+ if (item.accelerator) {424+ const accelerator = document.createElement("kbd");425+ accelerator.className =426+ "ms-auto shrink-0 font-medium font-sans text-secondary-label text-xs tracking-widest";427+ accelerator.style.cssText =428+ "margin-inline-start:auto;flex-shrink:0;color:var(--secondary-label);font-family:var(--font-sans,system-ui,sans-serif);font-size:0.75rem;font-weight:500;letter-spacing:0.1em;";
- apps/web/src/components/ThreadTerminalDrawer.tsx lines 737 to 737OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -693,0 +717,21 @@717+ const abortController = new AbortController();718+ terminalMenuAbortController = abortController;719+ selectionActionMenuOpenRef.current = true;720+ await runTerminalMenuRequest({721+ signal: abortController.signal,722+ isCurrentRequest: () => requestId === selectionActionRequestIdRef.current,723+ open: () =>724+ localApi.contextMenu725+ .show(726+ terminalContextMenuItems({727+ canAddToChat: selectionAction?.selection != null,728+ canCopy: selectionAction !== null,729+ }),730+ {731+ x: event.clientX,732+ y: event.clientY,733+ },734+ {735+ layout: "compact",736+ presentation: "styled",737+ restoreFocus: false,
- apps/web/src/components/ThreadTerminalDrawer.tsx line 684Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -681,4 +688,18 @@688+ if (terminalMenuAbortController === abortController) {689+ terminalMenuAbortController = null;690+ selectionActionMenuOpenRef.current = false;691+ }692+ if (openSelectionMenuRequestIdRef.current === requestId) {693+ openSelectionMenuRequestIdRef.current = null;694+ }695+ }),696+ perform: (clicked, isCurrent) =>697+ performTerminalMenuAction(clicked, nextAction, isCurrent),698+ reportOpenError: (error) => {699+ const activeTerminal = terminalRef.current;700+ if (activeTerminal) {701+ writeSystemMessage(702+ activeTerminal,703+ error instanceof Error ? error.message : "Unable to open the terminal context menu",704+ );681705 }682- });683- if (requestId !== selectionActionRequestIdRef.current || clicked === null) {684- return;
Adamulek123(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
ea62837d-c14d-4f66-af2d-8457c8c95f59You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share