Files
codex/codex-rs/tui/src/transcript_view/follow_control.rs
T
Felipe Coury 7c3f5e2cc2 Add search, selection, and link navigation to document previews (#61889)
## What changed

- Enable search, keyboard and mouse selection, and Markdown copying in sidebar document previews, including copying while offline.
- Navigate links with `Tab` and `Shift+Tab`, then open them with `Enter`. Open web links in the browser and resolve file links relative to the current document.
- Render local Markdown links as interactive labels and preserve distinct link occurrences across wrapping.
- Add document zoom, scroll indicators, and contextual footer hints. Disambiguate document tabs with matching filenames, including when titles are truncated.
- Cancel pending PRIMARY selection publication when a document is hidden and preserve the intended destination for composer clipboard pastes.

## Testing

Extend document preview coverage for search, selection, offline copying, link activation, hidden PRIMARY selections, and duplicate tab titles. Add rendering tests for local link labels and navigation across wrapped links.

GitOrigin-RevId: 80240fa580eed9dda971759afc49bc2bb909fcb5
2026-11-16 21:49:32 +00:00

113 lines
3.8 KiB
Rust

//! Return-to-latest affordance in the owned transcript's existing composer gap.
//! The control is hidden whenever the current final transcript row is visible.
//! Rendering owns the hit rectangle; hidden controls never intercept pointer input.
use super::*;
use crossterm::event::MouseButton;
use crossterm::event::MouseEvent;
use crossterm::event::MouseEventKind;
use ratatui::layout::Position as ScreenPosition;
use ratatui::widgets::Paragraph;
use unicode_width::UnicodeWidthStr;
#[derive(Default)]
pub(super) struct FollowControl {
area: Option<Rect>,
pointer: Option<ScreenPosition>,
pressed: bool,
}
impl TranscriptView {
pub(crate) fn render_follow_control(&mut self, area: Option<Rect>, buf: &mut Buffer) {
let Some(area) = area.filter(|area| !area.is_empty()) else {
self.follow_control = FollowControl::default();
return;
};
let Some(label) = self.follow_control_label(area.width) else {
self.follow_control = FollowControl::default();
return;
};
let width = label.width() as u16;
let target = Rect::new(
area.x + (area.width - width) / 2,
area.y,
width,
/*height*/ 1,
);
let hovered = self
.follow_control
.pointer
.is_some_and(|point| target.contains(point));
self.follow_control.area = Some(target);
let style =
crate::style::user_message_style().fg(crate::style::user_message_accent_color());
let style = if hovered {
style.reversed().bold()
} else {
style
};
Paragraph::new(label).style(style).render(target, buf);
}
pub(super) fn follow_control_label(&self, width: u16) -> Option<&'static str> {
if !self.show_follow_control
|| self.area.is_empty()
|| self.tail_visible
|| self.highlight.is_some()
|| self.selection.is_some()
|| self.is_search_editing()
{
return None;
}
let labels = if self.unseen_activity {
[
" New activity · ↓ Back to bottom · esc ",
" New activity · ↓ Bottom ",
" New · ↓ Bottom ",
" ↓ Bottom ",
" ↓ ",
]
} else {
[
" ↓ Back to bottom · esc ",
" ↓ Back to bottom ",
" ↓ Bottom · esc ",
" ↓ Bottom ",
" ↓ ",
]
};
labels
.into_iter()
.find(|label| label.width() <= usize::from(width))
}
pub(super) fn handle_follow_control_mouse(&mut self, event: MouseEvent) -> Option<ViewAction> {
let control = &mut self.follow_control;
let area = control.area?;
let point = ScreenPosition::new(event.column, event.row);
let was_hovered = control.pointer.is_some_and(|point| area.contains(point));
let inside = area.contains(point);
control.pointer = Some(point);
match event.kind {
MouseEventKind::Down(MouseButton::Left) if inside => {
control.pressed = true;
Some(ViewAction::Changed)
}
MouseEventKind::Up(MouseButton::Left) if control.pressed => {
control.pressed = false;
if inside {
self.jump_to_latest();
}
Some(ViewAction::Changed)
}
MouseEventKind::Drag(MouseButton::Left) if control.pressed => Some(ViewAction::Changed),
MouseEventKind::Moved if inside != was_hovered => Some(ViewAction::Changed),
_ => None,
}
}
}
#[cfg(test)]
#[path = "follow_control_tests.rs"]
mod tests;