mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Preserve local Markdown document targets in transcript rendering (#61880)
## What changed Retain eligible local `.md` and `.markdown` link targets as document metadata and allow transcript hit testing to resolve them when `document_links` is enabled. The flag defaults to disabled, and document targets are excluded from terminal OSC-8 links. Preserve link metadata through narrow table layouts, account for grapheme widths when remapping header links, and retain literal backslashes in POSIX file URI targets. Keep validated workspace artifact links usable as terminal hyperlinks. ## Testing Add regression coverage for opt-in document hit testing, narrow table link ranges, styled emoji and escaped pipes, POSIX file URI backslashes, and validated workspace artifact links. GitOrigin-RevId: e5d12c8558f5210eb66c17b5be8b28b7e80d414f
This commit is contained in:
@@ -116,7 +116,9 @@ impl TranscriptView {
|
||||
return None;
|
||||
}
|
||||
let visible = self.visible.get(usize::from(row - self.area.y))?;
|
||||
visible.layout.link_at(visible.row, column - self.area.x)
|
||||
visible
|
||||
.layout
|
||||
.link_at(visible.row, column - self.area.x, self.document_links)
|
||||
}
|
||||
|
||||
pub(crate) fn navigate_pager(
|
||||
|
||||
@@ -847,15 +847,15 @@ impl TextLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve the displayed link using the same destination policy as terminal OSC-8 output.
|
||||
pub(super) fn link_at(&self, row: usize, column: u16) -> Option<String> {
|
||||
/// Resolve an OSC-8 destination or a document target when the workspace enables previews.
|
||||
pub(super) fn link_at(&self, row: usize, column: u16, documents: bool) -> Option<String> {
|
||||
let row = self.rows.get(row)?;
|
||||
let column = usize::from(column).checked_sub(row.first_column - row.prefix_columns)?;
|
||||
row.line
|
||||
.hyperlinks
|
||||
.iter()
|
||||
.find(|link| link.columns.contains(&column))?
|
||||
.terminal_destination()
|
||||
.reader_destination(documents)
|
||||
}
|
||||
|
||||
fn visible_rows(&self, area: Rect, start_row: usize) -> impl Iterator<Item = (u16, &TextRow)> {
|
||||
|
||||
@@ -35,9 +35,15 @@ fn styled_tabs_use_row_stops_including_the_gutter() {
|
||||
);
|
||||
assert_eq!(
|
||||
(
|
||||
layout.link_at(/*row*/ 0, /*column*/ 16).as_deref(),
|
||||
layout.link_at(/*row*/ 0, /*column*/ 24).as_deref(),
|
||||
layout.link_at(/*row*/ 0, /*column*/ 13).as_deref()
|
||||
layout
|
||||
.link_at(/*row*/ 0, /*column*/ 16, /*documents*/ false)
|
||||
.as_deref(),
|
||||
layout
|
||||
.link_at(/*row*/ 0, /*column*/ 24, /*documents*/ false)
|
||||
.as_deref(),
|
||||
layout
|
||||
.link_at(/*row*/ 0, /*column*/ 13, /*documents*/ false)
|
||||
.as_deref()
|
||||
),
|
||||
(
|
||||
Some("https://example.com/one"),
|
||||
@@ -87,7 +93,9 @@ fn tab_stops_restart_after_wrapping_and_resize_preserves_source_and_links() {
|
||||
[(1, 3), (1, 8), (2, 2)],
|
||||
);
|
||||
assert_eq!(
|
||||
layout.link_at(/*row*/ 1, /*column*/ 8).as_deref(),
|
||||
layout
|
||||
.link_at(/*row*/ 1, /*column*/ 8, /*documents*/ false)
|
||||
.as_deref(),
|
||||
Some("https://example.com/x")
|
||||
);
|
||||
let wide = layout.rewrap(/*width*/ 40);
|
||||
|
||||
@@ -191,9 +191,14 @@ fn aligned_text_excludes_synthetic_leading_columns() {
|
||||
let mut line = HyperlinkLine::new(Line::default().right_aligned());
|
||||
line.push_span("wide".into(), Some("https://example.com"));
|
||||
let layout = TextLayout::new(vec![line], /*width*/ 8);
|
||||
assert_eq!(layout.link_at(/*row*/ 0, /*column*/ 3), None);
|
||||
assert_eq!(
|
||||
layout.link_at(/*row*/ 0, /*column*/ 4).as_deref(),
|
||||
layout.link_at(/*row*/ 0, /*column*/ 3, /*documents*/ false),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
layout
|
||||
.link_at(/*row*/ 0, /*column*/ 4, /*documents*/ false)
|
||||
.as_deref(),
|
||||
Some("https://example.com")
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -266,7 +271,8 @@ fn selected_revision_rewraps_both_directions_with_styles_and_indents() {
|
||||
restored.render(narrow_area, &mut restored_buffer, /*start_row*/ 0);
|
||||
assert_eq!(restored_buffer, original_buffer);
|
||||
assert_eq!(
|
||||
wide.link_at(/*row*/ 0, /*column*/ 8).as_deref(),
|
||||
wide.link_at(/*row*/ 0, /*column*/ 8, /*documents*/ false)
|
||||
.as_deref(),
|
||||
Some("https://example.com")
|
||||
);
|
||||
}
|
||||
@@ -419,3 +425,33 @@ fn background_stdin_copy_preserves_indentation_and_newlines() {
|
||||
assert!(layout.text().ends_with(stdin));
|
||||
assert_eq!(layout.rewrap(/*width*/ 48).text(), layout.text());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rendered_markdown_file_targets_are_only_interactive_in_the_workspace() {
|
||||
let markdown = "[Guide](./guide.md)\n\n| File |\n| --- |\n| [Notes](./notes.md) |";
|
||||
let lines = crate::markdown_render::render_markdown_lines_with_width_and_cwd(
|
||||
markdown,
|
||||
Some(40),
|
||||
/*cwd*/ None,
|
||||
);
|
||||
assert!(
|
||||
lines
|
||||
.iter()
|
||||
.flat_map(|line| &line.hyperlinks)
|
||||
.all(|link| link.terminal_destination().is_none())
|
||||
);
|
||||
let layout = TextLayout::new(lines, /*width*/ 40);
|
||||
let destinations = |documents| {
|
||||
let layout = &layout;
|
||||
(0..layout.row_count())
|
||||
.flat_map(|row| {
|
||||
(0..40).filter_map(move |column| layout.link_at(row, column, documents))
|
||||
})
|
||||
.collect::<std::collections::BTreeSet<_>>()
|
||||
};
|
||||
assert_eq!(destinations(false), std::collections::BTreeSet::new());
|
||||
assert_eq!(
|
||||
destinations(true),
|
||||
["./guide.md".to_owned(), "./notes.md".to_owned()].into()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user