feat(web): add link actions to the terminal context menu #12281
Closedflamboh(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/12281/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/ThreadTerminalDrawer.tsx line 798Resolvedby flamboh(GitHub profile, opens in a new tab)@@ -676,3 +756,6 @@676756 if (requestId !== selectionActionRequestIdRef.current || clicked === null) {677757 return;678758 }759+ if (linkText !== null) {760+ switch (clicked) {761+ case "open-terminal-link-preview":apps/web/src/components/ThreadTerminalDrawer.tsx line 774OutdatedResolvedby flamboh(GitHub profile, opens in a new tab)@@ -676,3 +756,19 @@676756 if (requestId !== selectionActionRequestIdRef.current || clicked === null) {677757 return;678758 }759+ if (linkText !== null) {760+ switch (clicked) {761+ case "open-terminal-link-preview":762+ await openTerminalLinkInIntegratedBrowser({763+ url: linkText,764+ threadRef,765+ openPreview,766+ fallbackToBrowser: () => openTerminalUrl(linkText, { forceBrowser: true }),767+ });768+ return;769+ case "open-terminal-link-browser":770+ openTerminalUrl(linkText, { forceBrowser: true });771+ return;772+ case "add-terminal-link-to-chat":773+ case "add-terminal-path-to-chat":774+ if (canAddLinkToChat()) onAddTerminalLink?.(terminalLinkChatText(linkText, cwd));apps/web/src/terminal/ghostty/surface.ts lines 1856 to 1856OutdatedResolvedby flamboh(GitHub profile, opens in a new tab)@@ -1815,3 +1853,4 @@18151853 return;18161854 }18171855 this.snapshot = this.core.snapshot();1856+ if (this.linkPinController.pinned !== null) this.linkPinController.clear();
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/web/src/terminal/ghostty/surface.ts lines 260 to 260OutdatedResolvedby flamboh(GitHub profile, opens in a new tab)@@ -249,3 +249,12 @@249249 readonly range: GhosttyCellRange;250250 }251251252+export function createTerminalLinkPinController(onChange?: () => void) {253+ let pinned: TerminalLinkWithRange | null = null;254+ let request = 0;255+ return {256+ get pinned() {257+ return pinned;258+ },259+ pin(link: TerminalLinkWithRange | null, pending: Promise<void> | void): void {260+ if (link === null) return;apps/web/src/components/ThreadTerminalDrawer.tsx line 773Resolvedby flamboh(GitHub profile, opens in a new tab)@@ -659,9 +735,16 @@659735 clearSelectionAction();660736 const selectionAction = readSelectionAction();661737 const requestId = selectionActionRequestIdRef.current;738+ const linkText = link?.text ?? null;739+ const reveal =740+ linkText !== null && !isTerminalUrl(linkText) ? readFileManagerReveal() : null;741+ const canOpenPreview =742+ linkText !== null && isTerminalUrl(linkText)743+ ? await canOpenTerminalLinkInPreview(linkText, threadRef)744+ : false;662745 let clicked: TerminalContextMenuAction | null;663746 try {664747 clicked = await localApi.contextMenu.show(665748 terminalContextMenuItems({666749 hasSelection: selectionAction !== null,667750 canAddToChat: canAddSelectionToChat(),
- apps/web/src/components/ThreadTerminalDrawer.tsx lines 273 to 273OutdatedResolvedby flamboh(GitHub profile, opens in a new tab)@@ -247,4 +255,19 @@247255 };248256 }249257250-export type TerminalContextMenuAction = "add-to-chat" | "copy" | "paste";258+export type TerminalContextMenuAction =259+ | "add-to-chat"260+ | "copy"261+ | "paste"262+ | "open-terminal-link-preview"263+ | "open-terminal-link-browser"264+ | "add-terminal-link-to-chat"265+ | "copy-terminal-link"266+ | "open-terminal-path"267+ | "reveal-terminal-path"268+ | "add-terminal-path-to-chat"269+ | "copy-terminal-path";270+271+export function terminalLinkChatText(text: string, cwd: string): string {272+ if (isTerminalUrl(text)) return text;273+ const path = splitFilePathPosition(text).path.replace(/[\\/]+$/, "") || "/";
- @@ -0,0 +1,9 @@1+import { useAtomValue } from "@effect/atom-react";2+import type { EnvironmentPresentation } from "@t3tools/client-runtime/connection";3+import {4+ isAtomCommandInterrupted,5+ squashAtomCommandFailure,6+ type AtomCommandResult,7+} from "@t3tools/client-runtime/state/runtime";8+import type { EnvironmentId, ServerConfig } from "@t3tools/contracts";9+import { Atom } from "effect/unstable/reactivity";
- apps/web/src/fileManagerReveal.ts lines 188 to 224Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +206,21 @@206+ : {207+ label: revealInFileExplorerLabelForManager(revealManagerName),208+ run: (targetPath: string) =>209+ openInEditor({210+ environmentId,211+ input: { cwd: targetPath, editor: "file-manager", reveal: true },212+ }),213+ };214+215+ return {216+ open: {217+ managerName: openManagerName,218+ run: (targetPath) =>219+ openInEditor({220+ environmentId,221+ input: { cwd: targetPath, editor: "file-manager" },222+ }),223+ },224+ reveal,225+ };226+}
- apps/web/src/terminal-links.ts lines 112 to 114Resolvedby flamboh(GitHub profile, opens in a new tab)@@ -105,3 +105,11 @@105105 return isWindowsAbsolutePath(value) || /[A-Za-z]:\\/.test(value);106106 }107107108+/** `C:` for a drive path, `\\\\server\\share` for a UNC path, else nothing. */109+function windowsVolumeRoot(cwd: string): string | null {110+ const normalized = cwd.replaceAll("/", "\\");111+ const drive = /^([A-Za-z]:)(?:\\|$)/.exec(normalized);112+ if (drive?.[1]) return drive[1];113+ if (!normalized.startsWith("\\\\")) return null;114+ const [server, share] = normalized.slice(2).split("\\");115+ return server && share ? `\\\\${server}\\${share}` : null;
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed