tui: keep out-of-cwd file links absolute

This commit is contained in:
pash
2026-03-02 09:38:42 -08:00
parent 0fd120461d
commit a67d1cd1a4
2 changed files with 14 additions and 2 deletions

View File

@@ -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<String>
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}"))
}

View File

@@ -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(