mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +00:00
## What changed - Add mouse selection, word and line selection, drag autoscrolling, and keyboard selection with `Ctrl+Space`. Support copying selected text and opening links with a modified click. - Anchor reading positions and selections to source text so resizing, streaming completion, and history pagination preserve the displayed content. Preserve hard line breaks, indentation, tabs, and graphemes when copying, while excluding display gutters and soft wraps. - Rejoin activity groups split across history pages while retaining the reader's displayed revision. - Distinguish confirmed clipboard writes from unconfirmed terminal requests, and retain native clipboard ownership after the transcript overlay closes. - Manage mouse capture and keyboard modes across overlay transitions, editor handoffs, and suspend/resume. ## Testing Add regression tests for selection during live updates and pagination, source-text copying across resize, clipboard confirmation and lifetime, and terminal mode restoration. GitOrigin-RevId: 6b2438f576567cbba755b2405915a25acf009b8d
104 lines
3.7 KiB
Rust
104 lines
3.7 KiB
Rust
//! Reconstruct logical styled lines from explicit wrapping provenance for resize and copy.
|
|
|
|
use std::ops::Range;
|
|
use std::sync::Arc;
|
|
|
|
use ratatui::text::Line;
|
|
use ratatui::text::Span;
|
|
|
|
use crate::terminal_hyperlinks::HyperlinkLine;
|
|
use crate::terminal_hyperlinks::LineWrapPolicy;
|
|
use crate::terminal_hyperlinks::LogicalLineSource;
|
|
use crate::width::display_width;
|
|
|
|
#[derive(Clone)]
|
|
pub(super) struct LogicalLine {
|
|
pub(super) line: HyperlinkLine,
|
|
pub(super) initial_indent: Line<'static>,
|
|
pub(super) subsequent_indent: Line<'static>,
|
|
pub(super) wrap_policy: LineWrapPolicy,
|
|
pub(super) right_reserve: u16,
|
|
pub(super) origin: LogicalLineSource,
|
|
}
|
|
|
|
pub(super) fn logical_lines(lines: &[HyperlinkLine]) -> Vec<LogicalLine> {
|
|
let mut logical: Vec<LogicalLine> = Vec::new();
|
|
for line in lines {
|
|
let source = line
|
|
.source
|
|
.clone()
|
|
.unwrap_or_else(|| LogicalLineSource::from_line(&line.line));
|
|
let previous = logical.last_mut().filter(|previous| {
|
|
Arc::ptr_eq(&previous.origin.text, &source.text)
|
|
&& previous.origin.range.end <= source.range.start
|
|
});
|
|
match previous {
|
|
Some(previous) => previous.append(line, source),
|
|
None => {
|
|
let mut entry = LogicalLine {
|
|
line: HyperlinkLine::new(Line::default().style(line.line.style)),
|
|
initial_indent: slice_line(&line.line, 0..source.prefix_bytes),
|
|
subsequent_indent: source.continuation_indent.clone(),
|
|
wrap_policy: source.wrap_policy,
|
|
right_reserve: source.right_reserve,
|
|
origin: source.clone(),
|
|
};
|
|
entry.origin.range.end = source.range.start;
|
|
entry.append(line, source);
|
|
logical.push(entry);
|
|
}
|
|
}
|
|
}
|
|
logical
|
|
}
|
|
|
|
impl LogicalLine {
|
|
fn append(&mut self, line: &HyperlinkLine, source: LogicalLineSource) {
|
|
self.line.line.spans.extend(
|
|
source
|
|
.styled_range(self.origin.range.end..source.range.start)
|
|
.spans,
|
|
);
|
|
let column = self.line.width();
|
|
let body = slice_line(
|
|
&line.line,
|
|
source.prefix_bytes..source.prefix_bytes + source.range.len(),
|
|
);
|
|
let prefix = slice_line(&line.line, 0..source.prefix_bytes);
|
|
let prefix_width = prefix.width();
|
|
let content_width = display_width(&source.text[source.range.clone()]);
|
|
self.line.line.spans.extend(body.spans);
|
|
self.line
|
|
.hyperlinks
|
|
.extend(line.hyperlinks.iter().filter_map(|link| {
|
|
let start = link.columns.start.max(prefix_width);
|
|
let end = link.columns.end.min(prefix_width + content_width);
|
|
(start < end).then(|| {
|
|
link.with_columns(column + start - prefix_width..column + end - prefix_width)
|
|
})
|
|
}));
|
|
self.line.line.alignment = line.line.alignment;
|
|
self.origin.range.end = source.range.end;
|
|
}
|
|
}
|
|
|
|
pub(super) fn slice_line(line: &Line<'_>, range: Range<usize>) -> Line<'static> {
|
|
let mut offset = 0;
|
|
let spans = line
|
|
.spans
|
|
.iter()
|
|
.filter_map(|span| {
|
|
let start = range.start.saturating_sub(offset).min(span.content.len());
|
|
let end = range.end.saturating_sub(offset).min(span.content.len());
|
|
offset += span.content.len();
|
|
(start < end).then(|| {
|
|
Span::styled(
|
|
span.content[start..end].to_owned(),
|
|
line.style.patch(span.style),
|
|
)
|
|
})
|
|
})
|
|
.collect::<Vec<_>>();
|
|
Line::from(spans).style(line.style)
|
|
}
|