Open source file links at line and column targets in the TUI (#61890)

## What changed

- Extend sidebar previews beyond Markdown to source files, including extensionless files. Preserve line and column targets such as `./Makefile#L12C3`, scroll to the target, and highlight its line and character.
- Render source previews with syntax highlighting and line numbers when space permits. Keep plain Markdown links rendered as Markdown, and show source when a location is specified.
- Show local link labels without appended destinations when workspace previews are available, and emphasize links on hover. Refresh rendering when preview availability changes.
- Limit source previews to 1 MiB and 10,000 lines, and disable document previews for Windows workspaces.

## Testing

Add coverage for extensionless link parsing, matching hover and click targets, streamed file citation metadata, and source navigation with CRLF input, tab reuse, and Escape handling.

GitOrigin-RevId: c2629b122628a4f5afa17df1890f63bd1c9bbcf6
This commit is contained in:
Felipe Coury
2026-11-16 21:50:03 +00:00
committed by copyberry
parent 7c3f5e2cc2
commit 3a51865c8c
30 changed files with 846 additions and 201 deletions
@@ -174,6 +174,63 @@ fn hover_links_match_wrapped_click_targets_and_refresh_after_scrolling() {
);
}
#[test]
fn workspace_file_links_show_the_title_with_subtle_hover_and_open_the_same_location() {
use crate::markdown_render::FileLink;
use crate::markdown_render::SourceLocation;
use ratatui::style::Modifier;
crate::markdown_render::preferences::set_document_links(/*enabled*/ true);
let (mut view, cells) = transcript(
"[Guide](./guide.md#L3C2) and [](./guide.md#L3C2)",
/*width*/ 32,
);
view.document_links = true;
let area = view.area;
let mut idle = Buffer::empty(area);
view.render(area, &mut idle, &cells);
let title = ScreenPosition::new(area.x + 3, area.y);
let path = ScreenPosition::new(area.x + 13, area.y);
let mut observations = vec![
crate::transcript_view::tests::text(&idle)
.trim()
.to_string(),
];
for (name, point) in [("title", title), ("filename", path)] {
let mut hovered = idle.clone();
view.paint_document_links(&mut hovered, Some(point));
observations.push(format!(
"{name}: underline={}, hover bold={}, background unchanged={}",
hovered[point].modifier.contains(Modifier::UNDERLINED),
hovered[point].modifier.contains(Modifier::BOLD),
hovered[point].bg == idle[point].bg,
));
view.handle_mouse(
mouse(MouseEventKind::Down(MouseButton::Left), point.x, point.y),
&cells,
);
let Some(ViewAction::OpenDocument(link)) = view.handle_mouse(
mouse(MouseEventKind::Up(MouseButton::Left), point.x, point.y),
&cells,
) else {
panic!("{name} click should open a document");
};
assert_eq!(
link,
FileLink {
path: "./guide.md".to_string(),
location: Some(SourceLocation { line: 3, column: 2 }),
},
);
}
insta::assert_snapshot!(observations.join("\n"), @"
• Guide and ./guide.md:3:2
title: underline=true, hover bold=true, background unchanged=true
filename: underline=false, hover bold=true, background unchanged=true
");
}
#[test]
fn shift_click_extends_a_double_clicked_word_in_both_directions() {
let (mut view, cells) = transcript("alpha beta gamma", /*width*/ 24);