@@ -3,6 +3,7 @@ import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
33import { resolveMobileMarkdownMediaSource } from "../../lib/markdownMediaSource" ;
44import { getBrowseDirectoryPath } from "@t3tools/client-runtime/state/projects" ;
55import { useState } from "react" ;
6+ import { StackActions , useNavigation } from "@react-navigation/native" ;
67import { RefreshControl , ScrollView , View } from "react-native" ;
78
89import { tryOpenExternalUrl } from "../../lib/openExternalUrl" ;
@@ -16,7 +17,11 @@ import {
1617} from "../threads/ThreadMarkdownImage" ;
1718import { ThreadMarkdownVideo } from "../threads/ThreadMarkdownVideo" ;
1819import { resolveMarkdownMediaPreview } from "../../lib/markdownMedia" ;
19- import { normalizeNativeMarkdownUrl } from "../../lib/markdownLinks" ;
20+ import {
21+ normalizeNativeMarkdownUrl ,
22+ resolveMarkdownLinkPresentation ,
23+ } from "../../lib/markdownLinks" ;
24+ import { AppText as Text } from "../../components/ui/AppText" ;
2025import { VideoPreviewModal , type VideoPreviewSource } from "../../components/VideoPreviewModal" ;
2126import { FilePreviewModal , type FilePreviewSource } from "../../components/FilePreviewModal" ;
2227import { useMarkdownImageSource } from "../../native/useMarkdownImageSource" ;
@@ -26,7 +31,7 @@ import {
2631 type MarkdownImageRenderer ,
2732 type NativeMarkdownTextStyle ,
2833} from "../../native/SelectableMarkdownText" ;
29- import { resolveWorkspaceFilePath } from "./filePath" ;
34+ import { fileRoutePathSegments , resolveWorkspaceFilePath } from "./filePath" ;
3035
3136interface MarkdownPreviewStyles {
3237 readonly nativeTextStyle : NativeMarkdownTextStyle ;
@@ -79,6 +84,7 @@ export function FileMarkdownPreview(props: {
7984 readonly threadId : ThreadId | null ;
8085 readonly onRefresh ?: ( ) => Promise < void > | void ;
8186} ) {
87+ const navigation = useNavigation ( ) ;
8288 const [ isPullRefreshing , setIsPullRefreshing ] = useState ( false ) ;
8389 const [ expandedFile , setExpandedFile ] = useState < FilePreviewSource | null > ( null ) ;
8490 const [ expandedVideo , setExpandedVideo ] = useState < VideoPreviewSource | null > ( null ) ;
@@ -107,6 +113,24 @@ export function FileMarkdownPreview(props: {
107113 captured : props . captured ,
108114 imageEmbed : true ,
109115 } ) ;
116+ const fileLink = resolveMarkdownLinkPresentation ( image . href ) ;
117+ if (
118+ ( preview && preview . kind !== "image" && preview . kind !== "video" ) ||
119+ ( ! props . captured && fileLink . kind === "file" && fileLink . line !== undefined )
120+ ) {
121+ const name =
122+ preview ?. source . name ?? ( fileLink . kind === "file" ? fileLink . label : "Open file" ) ;
123+ return (
124+ < Text
125+ accessibilityRole = "link"
126+ accessibilityLabel = { `Open ${ name } ` }
127+ onPress = { ( ) => openMedia ( image . href , true ) }
128+ style = { { color : styles . nativeTextStyle . linkColor } }
129+ >
130+ { name }
131+ </ Text >
132+ ) ;
133+ }
110134 if ( media ?. access === "direct" ) {
111135 if ( media . kind === "video" ) {
112136 return (
@@ -170,7 +194,21 @@ export function FileMarkdownPreview(props: {
170194 captured : props . captured ,
171195 imageEmbed,
172196 } ) ;
173- if ( ! media ) return false ;
197+ if ( ! media || media . kind === "file" ) {
198+ const fileLink = resolveMarkdownLinkPresentation ( href ) ;
199+ if ( props . captured || fileLink . kind !== "file" ) return false ;
200+ const params = {
201+ environmentId : String ( props . environmentId ) ,
202+ path : fileRoutePathSegments ( resolveWorkspaceFilePath ( markdownDirectory , fileLink . path ) ) ,
203+ ...( fileLink . line ? { line : String ( fileLink . line ) } : { } ) ,
204+ } ;
205+ if ( props . threadId ) {
206+ navigation . navigate ( "ThreadFile" , { ...params , threadId : String ( props . threadId ) } ) ;
207+ } else {
208+ navigation . dispatch ( StackActions . push ( "NewTaskFile" , { ...params , cwd : props . cwd } ) ) ;
209+ }
210+ return true ;
211+ }
174212 if ( media . kind === "video" ) setExpandedVideo ( media . source ) ;
175213 else setExpandedFile ( media . source ) ;
176214 return true ;
0 commit comments