From 58f0e21a77669301f1791d1752dbb787904a446a Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Fri, 4 Sep 2026 11:27:50 +0800 Subject: [PATCH] base: Stop auto scroll once the text selection gesture has ended Co-Authored-By: Claude Fable 5.1 --- crates/base/src/text_selection.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/base/src/text_selection.rs b/crates/base/src/text_selection.rs index b294805b64..180812e8b9 100644 --- a/crates/base/src/text_selection.rs +++ b/crates/base/src/text_selection.rs @@ -1458,6 +1458,11 @@ impl WindowSelectionState { window: Option<&Window>, cx: &mut Context, ) { + // A finished gesture keeps its anchor for shift-click extension; only + // a live drag may scroll. + if !self.is_selecting { + return; + } let Some(anchor) = self.anchor.as_ref().filter(|anchor| anchor.inside) else { return; }; @@ -3143,6 +3148,29 @@ mod tests { .unwrap(); } + #[gpui::test] + fn pointer_moves_after_a_click_do_not_auto_scroll(cx: &mut TestAppContext) { + let window = cx.add_window(|_, cx| WindowSelectionView { + selection: TextSelectionHandle::new("unused", cx), + }); + window + .update(cx, |_, window, cx| { + let state = cx.new(|_| WindowSelectionState::default()); + let participant = FakeParticipant::new("participant", cx); + state.update(cx, |state, cx| { + participant.register(state, 0., TextSelectionScopeId::default(), 0, cx); + // A click on text keeps its anchor so shift-click can extend it. + state.begin(point(px(1.), px(1.)), false, cx); + state.end(cx); + assert!(state.anchor.is_some()); + + state.update_in_window(point(px(1.), px(50.)), window, cx); + assert!(!state.auto_scroll.is_active()); + }); + }) + .unwrap(); + } + #[gpui::test] fn proxy_endpoints_break_equal_position_ties_by_document_order(cx: &mut TestAppContext) { cx.update(|cx| {