mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Prevent horizontal transcript selection from triggering autoscroll (#47137)
## Why Dragging horizontally along the top or bottom transcript row could trigger autoscroll, moving the text under the pointer while selecting it. ## What changed Require vertical pointer movement from the initial press row before selection autoscroll can begin. Remember that movement so a vertical drag can return to its starting edge and still autoscroll, and preserve the original pointer row across wheel scrolling. ## Testing Extend regression tests and snapshots for horizontal selection at both edges, stable selected text across repeated ticks, wheel scrolling before the first drag, and autoscroll after a vertical drag returns to its starting edge. GitOrigin-RevId: e13f3a80adbead1eecbeb281301667c8e12e1541
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
---
|
||||
source: tui/src/transcript_view_tests.rs
|
||||
expression: text(&selected)
|
||||
---
|
||||
row 22
|
||||
row 23
|
||||
row 24
|
||||
row 25
|
||||
row 26
|
||||
row 27
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
---
|
||||
source: tui/src/transcript_view_tests.rs
|
||||
expression: text(&selected)
|
||||
---
|
||||
row 22
|
||||
row 23
|
||||
row 24
|
||||
row 25
|
||||
row 26
|
||||
row 27
|
||||
+7
-8
@@ -1,18 +1,17 @@
|
||||
---
|
||||
source: tui/src/transcript_view/tests.rs
|
||||
assertion_line: 265
|
||||
source: tui/src/transcript_view_tests.rs
|
||||
expression: "frames.join(\"\\n\\n\")"
|
||||
---
|
||||
row 15
|
||||
row 16
|
||||
row 17
|
||||
row 18
|
||||
row 19
|
||||
row 20
|
||||
row 21
|
||||
row 22
|
||||
row 23
|
||||
|
||||
row 26
|
||||
row 27
|
||||
row 28
|
||||
row 29
|
||||
row 30
|
||||
row 31
|
||||
row 32
|
||||
row 33
|
||||
row 34
|
||||
|
||||
@@ -14,6 +14,8 @@ pub(super) struct Selection {
|
||||
pub(super) end: Anchor,
|
||||
pub(super) dragging: bool,
|
||||
pub(super) moved: bool,
|
||||
moved_vertically: bool,
|
||||
pointer_origin_row: u16,
|
||||
pub(super) resume_on_empty: bool,
|
||||
pub(super) pointer: Option<ScreenPosition>,
|
||||
pub(super) pressed_link: Option<String>,
|
||||
@@ -56,6 +58,8 @@ impl TranscriptView {
|
||||
preferred_column: None,
|
||||
dragging: true,
|
||||
moved: false,
|
||||
moved_vertically: false,
|
||||
pointer_origin_row: row,
|
||||
resume_on_empty: was_following,
|
||||
pointer: Some(ScreenPosition::new(column, row)),
|
||||
pressed_link: None,
|
||||
@@ -123,6 +127,7 @@ impl TranscriptView {
|
||||
};
|
||||
selection.snapshot.pinned.entry(end.key).or_insert(layout);
|
||||
selection.moved = true;
|
||||
selection.moved_vertically |= selection.pointer_origin_row != row;
|
||||
selection.pointer = Some(ScreenPosition::new(column, row));
|
||||
selection.preferred_column = None;
|
||||
self.pin_selection_range(&cells, &mut selection);
|
||||
@@ -272,7 +277,8 @@ impl TranscriptView {
|
||||
let Some(selection) = self
|
||||
.selection
|
||||
.as_ref()
|
||||
.filter(|selection| selection.dragging && selection.moved)
|
||||
// Horizontal selection on an edge row must not move the text under the pointer.
|
||||
.filter(|selection| selection.dragging && selection.moved_vertically)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -340,7 +340,7 @@ fn single_row_scrolling_crosses_an_entry_separator_in_both_directions() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clicking_an_edge_does_not_start_selection_autoscroll() {
|
||||
fn selecting_within_an_edge_row_does_not_start_selection_autoscroll() {
|
||||
let cells = vec![cell(
|
||||
(0..40)
|
||||
.map(|row| format!("row {row:02}\n"))
|
||||
@@ -367,6 +367,64 @@ fn clicking_an_edge_does_not_start_selection_autoscroll() {
|
||||
before
|
||||
);
|
||||
}
|
||||
view.handle_mouse(
|
||||
MouseEvent {
|
||||
kind: MouseEventKind::Drag(MouseButton::Left),
|
||||
column: 3,
|
||||
row: edge,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
},
|
||||
&cells,
|
||||
);
|
||||
let selected = render(&mut view, &cells, /*width*/ 20, /*height*/ 6);
|
||||
assert_eq!(text(&selected), text(&before));
|
||||
assert_eq!(view.selected_text(&cells).as_deref(), Some("row"));
|
||||
for _ in 0..10 {
|
||||
assert!(!view.tick_selection(&cells));
|
||||
assert_eq!(
|
||||
render(&mut view, &cells, /*width*/ 20, /*height*/ 6),
|
||||
selected
|
||||
);
|
||||
assert_eq!(view.selected_text(&cells).as_deref(), Some("row"));
|
||||
}
|
||||
insta::assert_snapshot!(
|
||||
format!("horizontal_selection_at_edge_{edge}"),
|
||||
text(&selected)
|
||||
);
|
||||
let drag = MouseEvent {
|
||||
kind: MouseEventKind::Drag(MouseButton::Left),
|
||||
column: 3,
|
||||
row: edge,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
view.handle_mouse(
|
||||
MouseEvent {
|
||||
kind: if edge == 0 {
|
||||
MouseEventKind::ScrollUp
|
||||
} else {
|
||||
MouseEventKind::ScrollDown
|
||||
},
|
||||
..drag
|
||||
},
|
||||
&cells,
|
||||
);
|
||||
render(&mut view, &cells, /*width*/ 20, /*height*/ 6);
|
||||
view.handle_mouse(drag, &cells);
|
||||
assert!(!view.tick_selection(&cells));
|
||||
// A deliberate vertical drag can return to its starting edge and still autoscroll.
|
||||
for row in [2, edge] {
|
||||
view.handle_mouse(
|
||||
MouseEvent {
|
||||
kind: MouseEventKind::Drag(MouseButton::Left),
|
||||
column: 3,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
},
|
||||
&cells,
|
||||
);
|
||||
render(&mut view, &cells, /*width*/ 20, /*height*/ 6);
|
||||
}
|
||||
assert!(view.tick_selection(&cells));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,6 +451,10 @@ fn wheel_scrolling_pauses_selection_autoscroll_until_the_next_drag() {
|
||||
row: edge,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
// Wheel input before the first drag must not lose the original physical row.
|
||||
view.handle_mouse(MouseEvent { kind, ..drag }, &cells);
|
||||
assert!(!view.tick_selection(&cells));
|
||||
render(&mut view, &cells, /*width*/ 20, /*height*/ 6);
|
||||
view.handle_mouse(drag, &cells);
|
||||
assert!(view.tick_selection(&cells));
|
||||
render(&mut view, &cells, /*width*/ 20, /*height*/ 6);
|
||||
|
||||
Reference in New Issue
Block a user