Limit pending input preview wrapping work (#39864)

## Why

Pending input previews display at most three wrapped rows, but previously wrapped every logical line before truncating the result. This made rendering do unnecessary work for very large multiline inputs.

## What changed

Limit pending steers, rejected steers, and queued follow-up inputs to four source lines before wrapping: three for the preview and one to detect overflow and render the ellipsis.

## Testing

Keep multiline preview coverage for queued messages and pending steers, including blank lines near the truncation boundary.

GitOrigin-RevId: 4c300b13532983ff9c3bdfbd62d6ca722ea3a5aa
This commit is contained in:
Benjamin Carlsson
2026-08-21 05:29:08 +00:00
committed by copyberry
parent 2151d3a5b7
commit 9ab176f488

View File

@@ -100,7 +100,10 @@ impl PendingInputPreview {
for steer in &self.pending_steers {
let wrapped = adaptive_wrap_lines(
steer.lines().map(|line| Line::from(line.dim())),
steer
.lines()
.take(PREVIEW_LINE_LIMIT + 1)
.map(|line| Line::from(line.dim())),
RtOptions::new(width as usize)
.initial_indent(Line::from("".dim()))
.subsequent_indent(Line::from(" ")),
@@ -121,7 +124,10 @@ impl PendingInputPreview {
for steer in &self.rejected_steers {
let wrapped = adaptive_wrap_lines(
steer.lines().map(|line| Line::from(line.dim())),
steer
.lines()
.take(PREVIEW_LINE_LIMIT + 1)
.map(|line| Line::from(line.dim())),
RtOptions::new(width as usize)
.initial_indent(Line::from("".dim()))
.subsequent_indent(Line::from(" ")),
@@ -138,7 +144,10 @@ impl PendingInputPreview {
for message in &self.queued_messages {
let wrapped = adaptive_wrap_lines(
message.lines().map(|line| Line::from(line.dim().italic())),
message
.lines()
.take(PREVIEW_LINE_LIMIT + 1)
.map(|line| Line::from(line.dim().italic())),
RtOptions::new(width as usize)
.initial_indent(Line::from("".dim()))
.subsequent_indent(Line::from(" ")),
@@ -282,7 +291,7 @@ mod tests {
let mut queue = PendingInputPreview::new();
queue
.queued_messages
.push("This is\na message\nwith many\nlines".to_string());
.push("This is\na message\nwith many\n\nlines".to_string());
let width = 40;
let height = queue.desired_height(width);
let mut buf = Buffer::empty(Rect::new(0, 0, width, height));
@@ -376,7 +385,7 @@ mod tests {
let mut queue = PendingInputPreview::new();
queue
.pending_steers
.push("First line\nSecond line\nThird line\nFourth line".to_string());
.push("First line\nSecond line\nThird line\n\nFourth line".to_string());
let width = 48;
let height = queue.desired_height(width);
let mut buf = Buffer::empty(Rect::new(0, 0, width, height));