From bc52f3ef0cf97c5affbdce1ed2422b70e31d55bc Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 22 Nov 2026 02:20:50 +0100 Subject: [PATCH] Canvas scroll bars: a thumb's pressed extent ends with its press (photocraft#16328) The press slot that keeps the extent a thumb was pressed at is kept until the component clears it, and the bars never did. After a thumb drag the bars kept unioning the drag's old extent, so a later zoom, pan or Overscroll change showed the old range: page presses stopped short and PhotoCraft's Overscroll test read a scroll room of 0. The release and a cancel now clear it. Co-Authored-By: Claude Opus 5.5 --- crates/ui-canvas/src/canvas/scrollbars/mod.rs | 17 ++++++++-- .../ui-canvas/tests/it/canvas/scrollbars.rs | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/crates/ui-canvas/src/canvas/scrollbars/mod.rs b/crates/ui-canvas/src/canvas/scrollbars/mod.rs index 6b64e1624..b61253890 100644 --- a/crates/ui-canvas/src/canvas/scrollbars/mod.rs +++ b/crates/ui-canvas/src/canvas/scrollbars/mod.rs @@ -496,8 +496,9 @@ impl Component for CanvasScrollbars<'_> { tip.close(cx); } let Some(view) = cx.value().copied() else { return }; - let held = cx.press_slot::().clone(); + let mut held = cx.press_slot::().clone(); let bars = self.bars(&view, cx.rect, cx.style, held.as_ref()); + let mut ended = false; let rtl = cx.flow.is_rtl(); let min_thumb = cx.style.look.min_thumb; for (key, axis, bar) in bars.each() { @@ -519,7 +520,13 @@ impl Component for CanvasScrollbars<'_> { // The press keeps the extent the thumb was pressed at for its drag. PressPhase::Down { .. } => *cx.press_slot::() = Some(HeldThumb::of(axis, &bar.span)), PressPhase::DragStart { .. } => cx.begin(), - PressPhase::Release { click: false, .. } => cx.commit(), + PressPhase::Release { click, .. } => { + if !click { + cx.commit(); + } + ended = true; + } + PressPhase::Cancel { .. } => ended = true, _ => {} } let range = match phase { @@ -548,6 +555,12 @@ impl Component for CanvasScrollbars<'_> { cx.set(next); } } + if ended { + // The pressed extent lasts as long as its press: the press slot is kept until it is cleared, and a stale + // extent would hold the bars' range after the drag (a later zoom, pan or Overscroll change). + *cx.press_slot::() = None; + held = None; + } self.held = held; } diff --git a/crates/ui-canvas/tests/it/canvas/scrollbars.rs b/crates/ui-canvas/tests/it/canvas/scrollbars.rs index 2aff72690..add8a164e 100644 --- a/crates/ui-canvas/tests/it/canvas/scrollbars.rs +++ b/crates/ui-canvas/tests/it/canvas/scrollbars.rs @@ -444,3 +444,34 @@ fn a_thumb_dragged_past_the_end_and_back_follows_the_pointer_in_the_same_drag() assert!(back.iter().any(|&x| x < at_end - 1.0), "the drag moves back: past the end {seen:?}, back {back:?}"); assert!((view.get().center.x - straight).abs() < 1.0, "back where a straight drag puts it: {} vs {straight}", view.get().center.x); } + +/// A thumb's pressed extent lasts only as long as its press: after the release the bars follow the view again. Here +/// the view zooms out after a thumb drag, and page presses on the track reach the new end (100 screen points of the +/// document left in view), as they do when no drag came first. The kept extent used to hold the range at the drag's +/// zoom (photocraft#16328). +#[trial] +fn after_a_thumb_drag_the_bars_follow_a_new_zoom() { + let large = Size::new(4000.0, 3000.0); + let zoomed_out = |view: CanvasView| CanvasView::new(view.rect, Point::new(large.width / 2.0, large.height / 2.0), 0.25); + let page_to_the_end = |fixture: &mut Fixture| { + let track = fixture.by_label("Horizontal scroll bar").expect("the track").rect; + for _ in 0..40 { + fixture.click_at(pos2(track.right() - 3.0, track.center().y)); + fixture.settle(); + } + }; + let (mut fixture, view) = centred_scrollbars(large, 1.0, true); + view.set(zoomed_out(view.get())); + fixture.settle(); + page_to_the_end(&mut fixture); + let fresh = shown_range(&view.get(), Axis::X).0; + assert!((fresh - (large.width - 400.0)).abs() < 1.0, "paging reaches the end: the last 400 units stay in view, shows from {fresh}"); + + let (mut fixture, view) = centred_scrollbars(large, 1.0, true); + drag_thumb(&mut fixture, "Horizontal scroll bar", vec2(40.0, 0.0)); + view.set(zoomed_out(view.get())); + fixture.settle(); + page_to_the_end(&mut fixture); + let first = shown_range(&view.get(), Axis::X).0; + assert!((first - fresh).abs() < 1.0, "after a thumb drag paging reaches the same end: shows from {first}, without the drag {fresh}"); +}