Make transcript mouse scroll speed configurable (#50209)

## What changed

Add `tui.mouse_scroll_speed` as a finite positive multiplier for transcript mouse wheel scrolling, including transcript overlays and session previews. Change the default from three rows to one row per wheel event; set the multiplier to `3.0` to retain the previous speed.

Fractional values accumulate movement across events and discard the remainder when direction reverses. For example, `0.5` scrolls one row every two events. Following the latest output pauses only when a whole row moves.

## Testing

Add tests for configuration validation, integer and fractional scroll speeds, direction changes, decimal accumulation, and following behavior. Extend local settings coverage to include a command-line override for the new setting.

GitOrigin-RevId: d355e246fd943415f0ce5a6affe849f77f3615e6
This commit is contained in:
Eric Traut
2026-10-02 06:50:10 +00:00
committed by copyberry
parent e3c2a83937
commit 4dd51f4a5f
22 changed files with 256 additions and 13 deletions
+22 -2
View File
@@ -3,6 +3,7 @@
//! Shift-click extends the existing selection from its original text unit.
//! Optional automatic copying happens only when a nonempty mouse selection is released.
//! Automatic copies retain the selection; explicit copies clear it after confirmed delivery.
//! Wheel input accumulates fractional rows and discards the remainder when direction reverses.
use crate::key_hint::KeyBindingListExt;
use crossterm::event::KeyCode;
@@ -232,8 +233,27 @@ impl TranscriptView {
selection.pointer = None;
}
match event.kind {
MouseEventKind::ScrollUp => self.scroll(cells, /*rows*/ -3),
MouseEventKind::ScrollDown => self.scroll(cells, /*rows*/ 3),
MouseEventKind::ScrollUp | MouseEventKind::ScrollDown => {
let direction = if event.kind == MouseEventKind::ScrollUp {
-1.0
} else {
1.0
};
if self.pending_mouse_scroll.signum() != direction {
self.pending_mouse_scroll = 0.0;
}
self.pending_mouse_scroll += direction * self.mouse_scroll_speed;
// Decimal speeds can land just short of a whole row after repeated addition.
let rounded = self.pending_mouse_scroll.round();
if rounded != 0.0 && (self.pending_mouse_scroll - rounded).abs() < 1e-9 {
self.pending_mouse_scroll = rounded;
}
let rows = self.pending_mouse_scroll as isize;
self.pending_mouse_scroll = self.pending_mouse_scroll.fract();
if rows != 0 {
self.scroll(cells, rows);
}
}
MouseEventKind::Down(MouseButton::Right) if inside => {
return self
.selected_text(cells)
+107 -1
View File
@@ -1,9 +1,115 @@
//! Link activation and selection extension share pointer gestures without losing selection anchors.
//! Mouse gestures preserve selection anchors and accumulate fractional transcript scrolling.
use super::*;
use crate::history_cell::AgentMarkdownCell;
use pretty_assertions::assert_eq;
#[test]
fn mouse_scroll_speed_scales_rows_and_accumulates_fractional_movement() {
use crate::history_cell::PlainHistoryCell;
use crate::transcript_view::tests::text;
let cells: Vec<Arc<dyn HistoryCell>> = vec![Arc::new(PlainHistoryCell::new(
(1..=24).map(|row| format!("row {row:02}").into()).collect(),
))];
let area = Rect::new(
/*x*/ 0, /*y*/ 0, /*width*/ 12, /*height*/ 4,
);
let mut frames = Vec::new();
for (speed, deltas) in [
(None, vec![-1, 1]),
(Some(0.5), vec![0, -1, 0, 0, 1]),
(Some(1.5), vec![-1, -2, 1, 2]),
(Some(3.0), vec![-3, 3]),
] {
let mut view = TranscriptView::default();
if let Some(speed) = speed {
view.mouse_scroll_speed = speed;
}
let mut buffer = Buffer::empty(area);
view.render(area, &mut buffer, &cells);
view.scroll(&cells, /*rows*/ -8);
view.render(area, &mut buffer, &cells);
let (index, mut row) = view.start(&cells);
let up_events = deltas.len().div_ceil(2);
for (event_index, delta) in deltas.into_iter().enumerate() {
let kind = if event_index < up_events {
MouseEventKind::ScrollUp
} else {
MouseEventKind::ScrollDown
};
view.handle_mouse(mouse(kind, /*column*/ 1, /*row*/ 1), &cells);
row = row.saturating_add_signed(delta);
assert_eq!(view.start(&cells), (index, row));
view.render(area, &mut buffer, &cells);
if event_index + 1 == up_events {
frames.push(format!(
"speed {speed:?}, {up_events} up events:\n{}",
text(&buffer)
));
}
}
}
insta::assert_snapshot!(frames.join("\n\n"));
}
#[test]
fn decimal_mouse_scroll_speeds_preserve_whole_rows() {
use crate::history_cell::PlainHistoryCell;
let cells: Vec<Arc<dyn HistoryCell>> = vec![Arc::new(PlainHistoryCell::new(
(1..=120)
.map(|row| format!("row {row:03}").into())
.collect(),
))];
let area = Rect::new(
/*x*/ 0, /*y*/ 0, /*width*/ 12, /*height*/ 4,
);
for speed in [0.1, 0.3] {
let mut view = TranscriptView {
mouse_scroll_speed: speed,
..TranscriptView::default()
};
view.render(area, &mut Buffer::empty(area), &cells);
view.scroll(&cells, /*rows*/ -40);
let (index, row) = view.start(&cells);
for (kind, direction) in [
(MouseEventKind::ScrollUp, -1),
(MouseEventKind::ScrollDown, 1),
] {
let (_, start_row) = view.start(&cells);
for event in 1..=100 {
view.handle_mouse(mouse(kind, /*column*/ 1, /*row*/ 1), &cells);
let rows = (f64::from(event) * speed).floor() as isize * direction;
assert_eq!(
view.start(&cells),
(index, start_row.saturating_add_signed(rows))
);
}
}
assert_eq!(view.start(&cells), (index, row));
}
}
#[test]
fn fractional_mouse_scroll_does_not_pause_following_until_a_row_moves() {
let (mut view, cells) = transcript(
"one\n\ntwo\n\nthree\n\nfour\n\nfive\n\nsix",
/*width*/ 12,
);
view.mouse_scroll_speed = 0.5;
view.handle_mouse(
mouse(MouseEventKind::ScrollUp, /*column*/ 4, /*row*/ 1),
&cells,
);
assert!(view.is_following());
view.handle_mouse(
mouse(MouseEventKind::ScrollUp, /*column*/ 4, /*row*/ 1),
&cells,
);
assert!(!view.is_following());
}
fn transcript(markdown: &str, width: u16) -> (TranscriptView, Vec<Arc<dyn HistoryCell>>) {
let cells: Vec<Arc<dyn HistoryCell>> = vec![Arc::new(AgentMarkdownCell::new(
markdown.into(),
@@ -0,0 +1,27 @@
---
source: tui/src/transcript_view/input_tests.rs
expression: "frames.join(\"\\n\\n\")"
---
speed None, 1 up events:
row 12
row 13
row 14
row 15
speed Some(0.5), 3 up events:
row 12
row 13
row 14
row 15
speed Some(1.5), 2 up events:
row 10
row 11
row 12
row 13
speed Some(3.0), 1 up events:
row 10
row 11
row 12
row 13