@@ -16,13 +16,16 @@ import React, {
1616import type { Components } from "react-markdown" ;
1717import ReactMarkdown from "react-markdown" ;
1818import remarkGfm from "remark-gfm" ;
19- import { openInPreferredEditor } from "../editorPreferences" ;
19+ import { useAppSettings } from "../appSettings" ;
20+ import { useCodeViewerStore } from "../codeViewerStore" ;
21+ import { openFileReference } from "../fileOpen" ;
2022import { resolveDiffThemeName , type DiffThemeName } from "../lib/diffRendering" ;
2123import { fnv1a32 } from "../lib/diffRendering" ;
2224import { LRUCache } from "../lib/lruCache" ;
2325import { useTheme } from "../hooks/useTheme" ;
2426import { resolveMarkdownFileLinkTarget } from "../markdown-links" ;
2527import { readNativeApi } from "../nativeApi" ;
28+ import { toastManager } from "./ui/toast" ;
2629
2730class CodeHighlightErrorBoundary extends React . Component <
2831 { fallback : ReactNode ; children : ReactNode } ,
@@ -236,8 +239,11 @@ function SuspenseShikiCodeBlock({
236239}
237240
238241function ChatMarkdown ( { text, cwd, isStreaming = false } : ChatMarkdownProps ) {
242+ const { settings } = useAppSettings ( ) ;
243+ const openFileInViewer = useCodeViewerStore ( ( state ) => state . openFile ) ;
239244 const { resolvedTheme } = useTheme ( ) ;
240245 const diffThemeName = resolveDiffThemeName ( resolvedTheme ) ;
246+ const openLinksExternally = settings . openLinksExternally ;
241247 const markdownComponents = useMemo < Components > (
242248 ( ) => ( {
243249 a ( { node : _node , href, ...props } ) {
@@ -255,9 +261,21 @@ function ChatMarkdown({ text, cwd, isStreaming = false }: ChatMarkdownProps) {
255261 event . stopPropagation ( ) ;
256262 const api = readNativeApi ( ) ;
257263 if ( api ) {
258- void openInPreferredEditor ( api , targetPath ) ;
264+ void openFileReference ( {
265+ api,
266+ cwd,
267+ targetPath,
268+ preferExternal : openLinksExternally ,
269+ openInViewer : openFileInViewer ,
270+ } ) . catch ( ( error ) => {
271+ toastManager . add ( {
272+ type : "error" ,
273+ title : "Unable to open file" ,
274+ description : error instanceof Error ? error . message : "An error occurred." ,
275+ } ) ;
276+ } ) ;
259277 } else {
260- console . warn ( "Native API not found. Unable to open file in editor ." ) ;
278+ console . warn ( "Native API not found. Unable to open file." ) ;
261279 }
262280 } }
263281 />
@@ -285,7 +303,7 @@ function ChatMarkdown({ text, cwd, isStreaming = false }: ChatMarkdownProps) {
285303 ) ;
286304 } ,
287305 } ) ,
288- [ cwd , diffThemeName , isStreaming ] ,
306+ [ cwd , diffThemeName , isStreaming , openFileInViewer , openLinksExternally ] ,
289307 ) ;
290308
291309 return (
0 commit comments