mirror of
https://github.com/openai/codex.git
synced 2026-09-17 12:23:33 +00:00
tui: keep out-of-cwd file links absolute
This commit is contained in:
@@ -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}"))
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user