diff --git a/codex-rs/tui/src/markdown_render.rs b/codex-rs/tui/src/markdown_render.rs index 80dd689672..54410bdfbc 100644 --- a/codex-rs/tui/src/markdown_render.rs +++ b/codex-rs/tui/src/markdown_render.rs @@ -1,4 +1,3 @@ -use crate::diff_render::display_path_for; use crate::render::highlight::highlight_code_to_lines; use crate::render::line_utils::line_to_static; use crate::wrapping::RtOptions; @@ -147,7 +146,10 @@ fn local_link_display_text(dest_url: &str, cwd: Option<&Path>) -> Option let (path, location_suffix) = split_local_link_destination(dest_url)?; let display_path = cwd.map_or_else( || path.display().to_string(), - |cwd| display_path_for(&path, cwd), + |cwd| match path.strip_prefix(cwd) { + Ok(stripped) => stripped.display().to_string(), + Err(_) => path.display().to_string(), + }, ); Some(format!("{display_path}{location_suffix}")) } diff --git a/codex-rs/tui/src/markdown_render_tests.rs b/codex-rs/tui/src/markdown_render_tests.rs index d34ed47ddf..3e3945b8e5 100644 --- a/codex-rs/tui/src/markdown_render_tests.rs +++ b/codex-rs/tui/src/markdown_render_tests.rs @@ -695,6 +695,16 @@ fn file_link_ignores_label_when_rendering_visible_target() { assert_eq!(text, expected); } +#[test] +fn file_link_outside_cwd_stays_absolute() { + let text = render_markdown_text_for_cwd( + "[ignored label](/Users/example/other-repo/src/main.rs:12)", + Path::new("/Users/example/code/codex"), + ); + let expected = Text::from(Line::from_iter(["/Users/example/other-repo/src/main.rs:12".cyan()])); + assert_eq!(text, expected); +} + #[test] fn file_link_normalizes_hash_anchor_for_terminal_clickability() { let text = render_markdown_text_for_cwd(