11import { Button } from "../../components/ui/Button" ;
22import { QuestionAttachments } from "./QuestionAttachments" ;
3- import type { EnvironmentId , RuntimeRequestId } from "@t3tools/contracts" ;
3+ import type { EnvironmentId , RuntimeRequestId , ThreadId } from "@t3tools/contracts" ;
44import type { ThreadUserInputQuestion } from "@t3tools/client-runtime/state/thread-requests" ;
55import {
66 markdownProseDirection ,
77 textDirection ,
88 type TextDirection ,
99} from "@t3tools/shared/textDirection" ;
10+ import { useNavigation } from "@react-navigation/native" ;
1011import { useRef } from "react" ;
1112import { Platform , Pressable , ScrollView , View , type LayoutChangeEvent } from "react-native" ;
1213import Animated , {
@@ -25,9 +26,15 @@ import { SymbolView } from "../../components/ui/AppSymbol";
2526import { AppText as Text } from "../../components/ui/AppText" ;
2627import { ControlPill } from "../../components/ui/ControlPill" ;
2728import { cn } from "../../lib/cn" ;
29+ import { resolveMarkdownLinkPresentation } from "../../lib/markdownLinks" ;
2830import { SelectableMarkdownText } from "../../native/SelectableMarkdownText" ;
2931import { useOpenPullRequest } from "../../native/useOpenPullRequest" ;
3032import { useMarkdownPreviewStyles } from "../files/FileMarkdownPreview" ;
33+ import {
34+ fileRoutePathSegments ,
35+ resolveFileLinkPath ,
36+ resolveWorkspaceRelativeFilePath ,
37+ } from "../files/filePath" ;
3138import { useLiveThreadLinkLabels } from "../../state/entities" ;
3239import {
3340 isPendingUserInputOptionSelected ,
@@ -37,6 +44,8 @@ import type { PendingUserInput } from "../../lib/threadActivity";
3744
3845export interface PendingUserInputCardProps {
3946 readonly environmentId : EnvironmentId ;
47+ readonly threadId : ThreadId ;
48+ readonly workspaceRoot : string | null ;
4049 readonly canOperateThread : boolean ;
4150 readonly pendingUserInput : PendingUserInput ;
4251 readonly maxHeight : DerivedValue < number > ;
@@ -77,11 +86,31 @@ function proseDirectionStyle(text: string, setDirection: TextDirection | undefin
7786function QuestionText ( props : {
7887 readonly markdown : string ;
7988 readonly environmentId : EnvironmentId ;
89+ readonly threadId : ThreadId ;
90+ readonly workspaceRoot : string | null ;
8091 readonly setDirection : TextDirection | undefined ;
8192} ) {
8293 const styles = useMarkdownPreviewStyles ( ) ;
8394 const markdown = useLiveThreadLinkLabels ( props . markdown , props . environmentId ) ;
84- const openLink = useOpenPullRequest ( ) ;
95+ const navigation = useNavigation ( ) ;
96+ const openPullRequest = useOpenPullRequest ( ) ;
97+ const openLink = ( href : string ) => {
98+ const link = resolveMarkdownLinkPresentation ( href ) ;
99+ if ( link . kind !== "file" ) {
100+ void openPullRequest ( href ) ;
101+ return ;
102+ }
103+ const path = resolveFileLinkPath ( props . workspaceRoot , link . path ) ;
104+ if ( path === null ) return ;
105+ navigation . navigate ( "ThreadFile" , {
106+ environmentId : String ( props . environmentId ) ,
107+ threadId : String ( props . threadId ) ,
108+ path : fileRoutePathSegments (
109+ resolveWorkspaceRelativeFilePath ( props . workspaceRoot , path ) ?? path ,
110+ ) ,
111+ ...( link . line ? { line : String ( link . line ) } : { } ) ,
112+ } ) ;
113+ } ;
85114 return (
86115 < SelectableMarkdownText
87116 markdown = { markdown }
@@ -91,7 +120,7 @@ function QuestionText(props: {
91120 textAlign = {
92121 Platform . OS === "android" ? undefined : props . setDirection === "rtl" ? "right" : "left"
93122 }
94- onLinkPress = { ( href ) => void openLink ( href ) }
123+ onLinkPress = { openLink }
95124 />
96125 ) ;
97126}
@@ -257,6 +286,8 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
257286 < QuestionText
258287 markdown = { question . question }
259288 environmentId = { props . environmentId }
289+ threadId = { props . threadId }
290+ workspaceRoot = { props . workspaceRoot }
260291 setDirection = { setDirection }
261292 />
262293 < View className = "gap-2" >
0 commit comments