You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by lu...@apache.org on 2026/10/20 05:36:50 UTC
(maka) 01/02: fix(gpui): give a wheel gesture to one scroll container
This is an automated email from the ASF dual-hosted git repository.
UncertaintyDeterminesYou4ndMe pushed a commit to branch fix/desktop-nested-scroll
in repository https://gitbox.apache.org/repos/asf/maka.git
commit bf1594e4af8bf0148df0b1fdaa187fc0a1ef737d
Author: Xun Lu <lu...@apache.org>
AuthorDate: Tue Oct 20 11:24:25 2026 +0800
fix(gpui): give a wheel gesture to one scroll container
A wheel or trackpad gesture, or a touch pan, over a scroll container
inside another moved both, because every Div and List scroll listener
under the pointer took every wheel event. In the desktop, scrolling a
tool's output box scrolled the conversation with it.
The window now keeps which container holds the current gesture. The
innermost container under the pointer that moves along the gesture's
axis takes it and keeps it to the gesture's end, at its own end too.
The containers around it leave the gesture's events to it, and so do
containers the scroll brings under the pointer. A container that
cannot move lets an event pass outward, so a box at its end hands the
next gesture to the page, as browsers chain scrolling. A gesture ends
with a Started phase, a wheel event at another position, or 300 ms in
which the holder took none of its events; a trackpad gesture ends on
such a pause only after its Ended phase, as a finger can rest on the
trackpad. Events still propagate to other wheel listeners, such as a
scrollbar's. A container that scrolls one axis with the wheel's other
axis takes no part.
Recorded in third-party/gpui-fast/SOURCE.md.
Generated-by: Claude Code
---
products/maka/cli/notices.json | 12 +-
third-party/gpui-fast/SOURCE.md | 4 +
third-party/gpui-fast/SOURCE.zh-CN.md | 4 +
.../gpui-fast/crates/gpui/src/elements/div.rs | 334 ++++++++++++++++++++-
.../gpui-fast/crates/gpui/src/elements/list.rs | 156 +++++++++-
third-party/gpui-fast/crates/gpui/src/gestures.rs | 98 ++++++
third-party/gpui-fast/crates/gpui/src/window.rs | 15 +
7 files changed, 605 insertions(+), 18 deletions(-)
diff --git a/products/maka/cli/notices.json b/products/maka/cli/notices.json
index 47563cf7c7..49fded7276 100644
--- a/products/maka/cli/notices.json
+++ b/products/maka/cli/notices.json
@@ -507,8 +507,8 @@
"third-party/gpui-fast/Cargo.toml": "4d549553fd2df7aba644dae5f978857c5ba22900d78d32bac905b8d75651b6c8",
"third-party/gpui-fast/LICENSE": "5f78a733701db49b73da93addad8cb74f816f3789ef30c3c0e959e943ecd99b4",
"third-party/gpui-fast/LICENSE-APACHE": "5f78a733701db49b73da93addad8cb74f816f3789ef30c3c0e959e943ecd99b4",
- "third-party/gpui-fast/SOURCE.md": "e4a930998288632d34f6af4be837065cae8b00eef96245707685038d28b7f824",
- "third-party/gpui-fast/SOURCE.zh-CN.md": "e4092ff9b70829c8085729d0722cc1bf8ebfae72296cf9477387a439168be804",
+ "third-party/gpui-fast/SOURCE.md": "7baa2379f99f8d0968410eabc3d398cd28d456eb5a6e18af7516a775870d3bfb",
+ "third-party/gpui-fast/SOURCE.zh-CN.md": "8137585669a8536cc21c59f2808b93d87aa38364884b99a02c95547353af1ced",
"third-party/gpui-fast/assets/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf": "975dcda37d80f038dcd143c22e33ca2d97a0cc5a929aace1c749153b0fe1afa5",
"third-party/gpui-fast/assets/fonts/ibm-plex-sans/license.txt": "91c25c350d3cac39da2736d74f7ba37ef648f5237a4e330a240615bc8d8c4360",
"third-party/gpui-fast/assets/fonts/lilex/Lilex-Regular.ttf": "8a467ad5a1941dc7c9cebaee34e3ed9364a73b48393034e363e4b528bd711d04",
@@ -547,11 +547,11 @@
"third-party/gpui-fast/crates/gpui/src/elements/canvas.rs": "3e09646e725d31c10a88be290c146d6a6e829e0be173e6bc82c138461668e646",
"third-party/gpui-fast/crates/gpui/src/elements/container_query.rs": "7e72aab18967e7e16ebbe38c535caf2ac6f881a62cf9f6045922fbeb8a06df07",
"third-party/gpui-fast/crates/gpui/src/elements/deferred.rs": "af8780d3197e8795f7920aa42920d676f1a8bc194af8d8cc35c508b8fc8af500",
- "third-party/gpui-fast/crates/gpui/src/elements/div.rs": "497ec3a12fa1eef106ef683b2ce17344ca21ca2716b50cfd8e6388069640ea28",
+ "third-party/gpui-fast/crates/gpui/src/elements/div.rs": "da566e57e3b7dedb7b8b06bfe489baf677eeb7cc2244f42a5e284308e2f330bc",
"third-party/gpui-fast/crates/gpui/src/elements/div/scroll.rs": "3751cc9754a3bc48136f816a10eed5a0d80dc7747e417f5e16a43440b6b304b0",
"third-party/gpui-fast/crates/gpui/src/elements/image_cache.rs": "e4540d7e92bc63bbaaf703df42338bbfabca764e34b7244880460d38962e14c4",
"third-party/gpui-fast/crates/gpui/src/elements/img.rs": "c196cb1ed3db30ab3141b036c84288a22e04de2b53b687e1d86fe732420374e3",
- "third-party/gpui-fast/crates/gpui/src/elements/list.rs": "752fd9dac5ce29c411f36ac2c6c4b665a1a65068eccb3f0fc50dac0bd690b347",
+ "third-party/gpui-fast/crates/gpui/src/elements/list.rs": "9f436755245f33b161620dcd8f79bf2a0a77b778b51dc3d125a30ff5bbda0c43",
"third-party/gpui-fast/crates/gpui/src/elements/mod.rs": "447ab5d960591744b9f193bbf9af562b5fbf9d8fd156e179584031e6f464d632",
"third-party/gpui-fast/crates/gpui/src/elements/surface.rs": "f2ec6f75528c2e9116255303fc7bb7c79cefc3fcae52f5bb64bc13e171cbb2fb",
"third-party/gpui-fast/crates/gpui/src/elements/svg.rs": "ab5412945c36fd0087e95a1544d610cf9308e906b3059835b4c49f98f4b9279e",
@@ -625,7 +625,7 @@
"third-party/gpui-fast/crates/gpui/src/fast/text_style.rs": "37bdddfd10919e8281d3a6ae236a8f869c4b6f60f2e8508cebaca523fea31138",
"third-party/gpui-fast/crates/gpui/src/fast/windows_manifest.rs": "2180789e5d545e4a77e4a6f56584de05908cf7f6a9bdc642f378c65a3723b9d6",
"third-party/gpui-fast/crates/gpui/src/geometry.rs": "900fc506a964cda44ed0cf1f97c01ff28d7268c87c9eeadbf7a4f1bb50e33edd",
- "third-party/gpui-fast/crates/gpui/src/gestures.rs": "1d640c41d75ee526d7f67c319057b40a098fcbd9dde5e1e551690ddcd4c066d0",
+ "third-party/gpui-fast/crates/gpui/src/gestures.rs": "0a84d9cdc0521d2c57772956d12e4238fb14bd992a38cbb41595837f907316cc",
"third-party/gpui-fast/crates/gpui/src/global.rs": "c52ddc647f712282a3a1f3629f864d0868966169fee7aff5f1f8d27e67f3f077",
"third-party/gpui-fast/crates/gpui/src/gpui.rs": "3da43f4a892b0ed8fcf75e3bd46fee5212e57d0e722598ed86b4752f9bc20d31",
"third-party/gpui-fast/crates/gpui/src/input.rs": "1e27952de8d447b268db7894f74fb41dad65a65c7d872466f589917b023a295d",
@@ -679,7 +679,7 @@
"third-party/gpui-fast/crates/gpui/src/text_system/line_wrapper.rs": "e96b639b5399340b9c716f875deb5b35e2ca29562235336f1ae8489e83d6d376",
"third-party/gpui-fast/crates/gpui/src/util.rs": "04397f667bf5d890cce690b96441cd5b8f5eb0a5dd2942ce27b0314be38fa636",
"third-party/gpui-fast/crates/gpui/src/view.rs": "eb93d6e4e2354be24d475862d66f97658f263bbc889788ce33bf5dac43576cac",
- "third-party/gpui-fast/crates/gpui/src/window.rs": "4afd55648e0dd2619f4857f31ab05c6a5020ff694c40f7163678f7b9822e4606",
+ "third-party/gpui-fast/crates/gpui/src/window.rs": "9e38e4d2df2864a6acdbb53facd206073709acc19aa471d33dd9e13162c4009a",
"third-party/gpui-fast/crates/gpui/src/window/a11y.rs": "d6b698deb5b8ae3e07e31e8c6a8e0a76d37fa63c88655cc0ea10df71c65362cf",
"third-party/gpui-fast/crates/gpui/src/window/a11y/debug.rs": "83d0693effdc98e64a083b217dbb09623f03f8f2b55db4a10f567aee977985d8",
"third-party/gpui-fast/crates/gpui/src/window/input_scope.rs": "7eed12d39d100e2b74cab5092c9f8a5c827fe5ec9152c4827e09e9ca28934c78",
diff --git a/third-party/gpui-fast/SOURCE.md b/third-party/gpui-fast/SOURCE.md
index f8498e5c01..800792ec0c 100644
--- a/third-party/gpui-fast/SOURCE.md
+++ b/third-party/gpui-fast/SOURCE.md
@@ -102,3 +102,7 @@ Programmatic list offsets still bump their original dependency version, includin
## List rows keep their layout-time element states (2026-10-16)
Backported from upstream pull request [#73](https://github.com/longbridge/gpui-fast/pull/73) (commit `97bff7005ef4e5971237fcf890262947cff21b46`) until it is merged. When a frame keeps a list row on the list's scroll layer, the element states that the row's render and `request_layout` took are now kept with the row and carried with its prepaint records; before, they were dropped at the end of the first frame that kept the row. gpui-kit's `TextView` keeps a parsed document of more than 4 K [...]
+
+## A wheel gesture scrolls one container (2026-10-20)
+
+Maka's own change. A wheel or trackpad gesture, or a touch pan, over a scroll container inside another, such as a tool's output box in a conversation list, moved both, because every `Div` and `List` scroll listener under the pointer took every wheel event. `Window` now keeps a `ScrollLatch` (`crates/gpui/src/gestures.rs`). The innermost container under the pointer that moves along the gesture's axis (the axis of its larger delta) takes the gesture and keeps it until the gesture ends, at [...]
diff --git a/third-party/gpui-fast/SOURCE.zh-CN.md b/third-party/gpui-fast/SOURCE.zh-CN.md
index 0a13518a15..1c64d211c7 100644
--- a/third-party/gpui-fast/SOURCE.zh-CN.md
+++ b/third-party/gpui-fast/SOURCE.zh-CN.md
@@ -77,3 +77,7 @@ Window 可根据原 ClickInputState interruption 创建不可 clone 的 InputGes
## 列表行保留布局期的元素状态(2026-10-16)
在上游合并前,回移上游拉取请求 [#73](https://github.com/longbridge/gpui-fast/pull/73)(提交 `97bff7005ef4e5971237fcf890262947cff21b46`)。某帧沿用列表滚动图层里的行时,该行在渲染和 `request_layout` 中取得的元素状态现在随行保存,并随其 prepaint 记录一起带入新帧;此前它们在第一次沿用该行的帧结束时被丢弃。gpui-kit 的 `TextView` 把超过 4 KB 的已解析文档存为这种状态,状态新建时在后台重新解析,所以在高于视口的 markdown 行内滚动时,该行会有一帧按空文档的高度布局。在另一列表的行布局期间布局的行(内层 `ListSizingBehavior::Infer` 列表的行)属于那一行,不再记成外层列表的行。改动在 `crates/gpui/src/fast/layers/lists.rs`,另有 `crates/gpui/src/fast/layout.rs` 中的一个访问函数,以及 `crates/gpui/src/fas [...]
+
+## 一次滚轮手势只滚动一个容器(2026-10-20)
+
+Maka 自己的改动。滚动容器嵌在另一个滚动容器里时(例如对话列表里的工具输出框),在它上面的一次滚轮或触控板手势(或一次触摸拖动)会让两者一起滚动,因为指针下每个 `Div` 和 `List` 的滚动监听器都会处理每个滚轮事件。现在 `Window` 持有一个 `ScrollLatch`(`crates/gpui/src/gestures.rs`):指针下沿手势方向(增量较大的那一轴)真正滚动了的最内层容器取得这次手势,直到手势结束,滚到尽头也不放手。它外层的容器(监听器在它之后运行)把这次手势的事件留给它,滚动中移到指针下的容器也不接手。滚不动的容器让事件继续向外传,所以框已在尽头时,下一次手势交给页面,与浏览器的滚动链一致;vendored GPUI Kit 的 `ScrollableMask` 在边缘把事件交给外层容器的行为也保持不变。手势在以下情况结束:收到 `TouchPhase::Started` 事件、滚轮事件位�
��改变、或取得手势的容器 300 毫秒内没有处理它的事件。以 `TouchPhase::Started` 开始的手势,要在收到 `TouchPh [...]
diff --git a/third-party/gpui-fast/crates/gpui/src/elements/div.rs b/third-party/gpui-fast/crates/gpui/src/elements/div.rs
index 06c2f821f5..d29e134d28 100644
--- a/third-party/gpui-fast/crates/gpui/src/elements/div.rs
+++ b/third-party/gpui-fast/crates/gpui/src/elements/div.rs
@@ -15,8 +15,9 @@
//! and Tailwind-like styling that you can use to build your own custom elements. Div is
//! constructed by combining these two systems into an all-in-one element.
+use crate::gestures::{ScrollLatch, ScrollTurn};
use crate::{
- AccessibilityClickEvent, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, App, Bounds,
+ AccessibilityClickEvent, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, App, Axis, Bounds,
ClickEvent, DispatchPhase, Display, Element, ElementId, Entity, EntityId, ExternalDragPayload,
ExternalDragPayloadSource, FileDropEvent, FocusHandle, Global, GlobalElementId, Hitbox,
HitboxBehavior, HitboxId, InspectorElementId, IntoElement, IsZero, KeyContext, KeyDownEvent,
@@ -3729,6 +3730,11 @@ impl Interactivity {
let allow_concurrent_scroll = style.allow_concurrent_scroll;
let restrict_scroll_to_axis = style.restrict_scroll_to_axis;
let line_height = window.line_height();
+ // How far it can move, as laid out for this frame, so an event
+ // that would only push it past an edge is seen not to move it.
+ let scroll_max = self.max_scroll_offset(hitbox.bounds, style, window);
+ // The offset's cell stays the same from frame to frame.
+ let owner = Rc::as_ptr(&scroll_offset) as *const () as usize;
let hitbox = hitbox.clone();
let current_view = window.current_view();
let subtrees = crate::fast::retained::enclosing_retained_subtrees(window);
@@ -3748,11 +3754,14 @@ impl Interactivity {
.filter(&mut delta, event.touch_phase);
}
+ // Whether it scrolls with the wheel's other axis.
+ let mut crosswise = false;
let mut delta_x = match overflow.x {
Overflow::Scroll if !delta.x.is_zero() => delta.x,
Overflow::Scroll
if !restrict_scroll_to_axis && overflow.y != Overflow::Scroll =>
{
+ crosswise = !delta.y.is_zero();
delta.y
}
_ => Pixels::ZERO,
@@ -3762,10 +3771,15 @@ impl Interactivity {
Overflow::Scroll
if !restrict_scroll_to_axis && overflow.x != Overflow::Scroll =>
{
+ crosswise = !delta.x.is_zero();
delta.x
}
_ => Pixels::ZERO,
};
+ let turn = (!crosswise).then(|| window.scroll_latch.turn(owner));
+ if turn == Some(ScrollTurn::Elsewhere) {
+ return;
+ }
if !allow_concurrent_scroll && !delta_x.is_zero() && !delta_y.is_zero() {
if delta_x.abs() > delta_y.abs() {
delta_y = Pixels::ZERO;
@@ -3773,9 +3787,25 @@ impl Interactivity {
delta_x = Pixels::ZERO;
}
}
- scroll_offset.y += delta_y;
- scroll_offset.x += delta_x;
- if *scroll_offset != old_scroll_offset {
+ scroll_offset.y = (scroll_offset.y + delta_y).clamp(-scroll_max.y, px(0.));
+ scroll_offset.x = (scroll_offset.x + delta_x).clamp(-scroll_max.x, px(0.));
+ let moved = *scroll_offset != old_scroll_offset;
+ let moved_along = match ScrollLatch::axis(delta) {
+ Axis::Vertical => scroll_offset.y != old_scroll_offset.y,
+ Axis::Horizontal => scroll_offset.x != old_scroll_offset.x,
+ };
+ // The gesture is this container's once it moves it along
+ // the gesture's axis. The containers around it, whose
+ // listeners run after this one, then leave the event
+ // alone (`ScrollLatch`); other listeners still see it.
+ if let Some(turn) = turn
+ && (moved_along || turn == ScrollTurn::Held)
+ {
+ window
+ .scroll_latch
+ .hold(owner, cx.background_executor().now());
+ }
+ if moved {
if let Some(handle) = scroll_handle.as_ref().and_then(Weak::upgrade) {
let mut state = handle.borrow_mut();
state.note_reading_intent();
@@ -6454,4 +6484,300 @@ mod tests {
assert_eq!(bounds("cell-1").origin.x, px(100.));
assert_eq!(bounds("cell-2").origin.x, px(300.));
}
+
+ /// A page 200px tall that scrolls, holding 50px of rows, a box 100px
+ /// tall that scrolls `box_rows` rows of 20px, or as many columns 20px
+ /// wide sideways, and 400px of rows. Counts the wheel events the page's
+ /// own listener sees.
+ struct NestedScroll {
+ page: ScrollHandle,
+ boxed: ScrollHandle,
+ box_rows: usize,
+ sideways: bool,
+ page_wheel_events: Rc<Cell<usize>>,
+ }
+
+ impl Render for NestedScroll {
+ fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
+ let page_wheel_events = self.page_wheel_events.clone();
+ div().size_full().child(
+ div()
+ .id("page")
+ .w(px(200.))
+ .h(px(200.))
+ .overflow_y_scroll()
+ .track_scroll(&self.page)
+ .on_scroll_wheel(move |_, _, _| {
+ page_wheel_events.set(page_wheel_events.get() + 1)
+ })
+ .child(div().w_full().h(px(50.)))
+ .child(if self.sideways {
+ div()
+ .id("box")
+ .flex()
+ .w_full()
+ .h(px(100.))
+ .flex_none()
+ .overflow_x_scroll()
+ .track_scroll(&self.boxed)
+ .children(
+ (0..self.box_rows).map(|_| div().w(px(20.)).h_full().flex_none()),
+ )
+ } else {
+ div()
+ .id("box")
+ .w_full()
+ .h(px(100.))
+ .flex_none()
+ .overflow_y_scroll()
+ .track_scroll(&self.boxed)
+ .children(
+ (0..self.box_rows).map(|_| div().w_full().h(px(20.)).flex_none()),
+ )
+ })
+ .child(div().w_full().h(px(400.)).flex_none()),
+ )
+ }
+ }
+
+ /// Where the pointer is over the box before the page scrolls, and over
+ /// the page alone, 10px above the box.
+ const OVER_BOX: Point<Pixels> = point(px(20.), px(100.));
+ const OVER_PAGE: Point<Pixels> = point(px(20.), px(40.));
+
+ struct NestedScrollWindow {
+ window: AnyWindowHandle,
+ page: ScrollHandle,
+ boxed: ScrollHandle,
+ page_wheel_events: Rc<Cell<usize>>,
+ }
+
+ impl NestedScrollWindow {
+ fn open(cx: &mut TestAppContext, box_rows: usize) -> Self {
+ Self::open_with(cx, box_rows, false)
+ }
+
+ fn open_with(cx: &mut TestAppContext, box_rows: usize, sideways: bool) -> Self {
+ let page = ScrollHandle::new();
+ let boxed = ScrollHandle::new();
+ let page_wheel_events = Rc::new(Cell::new(0));
+ let window: AnyWindowHandle = cx
+ .add_window({
+ let page = page.clone();
+ let boxed = boxed.clone();
+ let page_wheel_events = page_wheel_events.clone();
+ move |_, _| NestedScroll {
+ page,
+ boxed,
+ box_rows,
+ sideways,
+ page_wheel_events,
+ }
+ })
+ .into();
+ cx.update_window(window, |_, window, cx| window.draw(cx).clear(cx))
+ .unwrap();
+ Self {
+ window,
+ page,
+ boxed,
+ page_wheel_events,
+ }
+ }
+
+ /// Dispatches a wheel event that moves the content up by `dy`, and
+ /// draws a frame.
+ fn wheel(
+ &self,
+ cx: &mut TestAppContext,
+ position: Point<Pixels>,
+ dy: f32,
+ touch_phase: TouchPhase,
+ ) {
+ self.wheel_xy(cx, position, 0., dy, touch_phase);
+ }
+
+ /// Dispatches a wheel event that moves the content left by `dx` and
+ /// up by `dy`, and draws a frame.
+ fn wheel_xy(
+ &self,
+ cx: &mut TestAppContext,
+ position: Point<Pixels>,
+ dx: f32,
+ dy: f32,
+ touch_phase: TouchPhase,
+ ) {
+ cx.update_window(self.window, |_, window, cx| {
+ window.dispatch_event(
+ crate::PlatformInput::ScrollWheel(ScrollWheelEvent {
+ position,
+ delta: crate::ScrollDelta::Pixels(point(px(-dx), px(-dy))),
+ modifiers: Default::default(),
+ touch_phase,
+ }),
+ cx,
+ );
+ window.draw(cx).clear(cx);
+ })
+ .unwrap();
+ }
+
+ /// Dispatches a touch of `phase` at `position`, and draws a frame.
+ fn touch(&self, cx: &mut TestAppContext, position: Point<Pixels>, phase: TouchPhase) {
+ cx.update_window(self.window, |_, window, cx| {
+ window.dispatch_event(
+ TouchEvent {
+ id: TouchId(1),
+ phase,
+ position,
+ predicted_position: None,
+ force: None,
+ }
+ .to_platform_input(),
+ cx,
+ );
+ window.draw(cx).clear(cx);
+ })
+ .unwrap();
+ }
+
+ /// How far the page and the box have scrolled.
+ fn offsets(&self) -> (Pixels, Pixels) {
+ (-self.page.offset().y, -self.boxed.offset().y)
+ }
+ }
+
+ #[gpui::test]
+ fn test_wheel_over_a_nested_box_scrolls_only_the_box(cx: &mut TestAppContext) {
+ let nested = NestedScrollWindow::open(cx, 20);
+ nested.wheel(cx, OVER_BOX, 30., TouchPhase::Started);
+ assert_eq!(nested.offsets(), (px(0.), px(30.)));
+ nested.wheel(cx, OVER_BOX, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(0.), px(60.)));
+ // The page's own wheel listener still sees the events.
+ assert_eq!(nested.page_wheel_events.get(), 2);
+ }
+
+ #[gpui::test]
+ fn test_a_gesture_stays_with_a_nested_box_at_its_end(cx: &mut TestAppContext) {
+ // The box's 20 rows scroll 300px.
+ let nested = NestedScrollWindow::open(cx, 20);
+ nested.wheel(cx, OVER_BOX, 280., TouchPhase::Started);
+ nested.wheel(cx, OVER_BOX, 50., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(0.), px(300.)));
+ nested.wheel(cx, OVER_BOX, 50., TouchPhase::Moved);
+ nested.wheel(cx, OVER_BOX, 50., TouchPhase::Ended);
+ assert_eq!(nested.offsets(), (px(0.), px(300.)));
+
+ // The next gesture finds the box at its end and scrolls the page.
+ nested.wheel(cx, OVER_BOX, 40., TouchPhase::Started);
+ assert_eq!(nested.offsets(), (px(40.), px(300.)));
+ // Scrolling back over the box is the page's too, for this gesture.
+ nested.wheel(cx, OVER_BOX, -20., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(20.), px(300.)));
+ // The next gesture back scrolls the box.
+ nested.wheel(cx, OVER_BOX, -20., TouchPhase::Started);
+ assert_eq!(nested.offsets(), (px(20.), px(280.)));
+ }
+
+ #[gpui::test]
+ fn test_a_page_gesture_passes_over_a_nested_box(cx: &mut TestAppContext) {
+ let nested = NestedScrollWindow::open(cx, 20);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Started);
+ assert_eq!(nested.offsets(), (px(30.), px(0.)));
+ // The box is now under the pointer, at y 20 to 120, and then at -10
+ // to 90.
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(90.), px(0.)));
+ }
+
+ #[gpui::test]
+ fn test_a_nested_box_that_fits_passes_the_wheel_out(cx: &mut TestAppContext) {
+ let nested = NestedScrollWindow::open(cx, 3);
+ nested.wheel(cx, OVER_BOX, 30., TouchPhase::Started);
+ nested.wheel(cx, OVER_BOX, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(60.), px(0.)));
+ }
+
+ #[gpui::test]
+ fn test_a_gesture_ends_when_the_pointer_moves(cx: &mut TestAppContext) {
+ // A mouse wheel's ticks come as moves, without a start or an end.
+ let nested = NestedScrollWindow::open(cx, 20);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ // Over the box now, which leaves the tick to the page.
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(60.), px(0.)));
+ nested.wheel(cx, point(px(25.), px(40.)), 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(60.), px(30.)));
+ }
+
+ #[gpui::test]
+ fn test_a_mouse_wheel_gesture_ends_after_a_pause(cx: &mut TestAppContext) {
+ let nested = NestedScrollWindow::open(cx, 20);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ cx.executor()
+ .advance_clock(crate::gestures::SCROLL_LATCH_IDLE / 2);
+ // Over the box now, which leaves the tick to the page.
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(60.), px(0.)));
+
+ cx.executor()
+ .advance_clock(crate::gestures::SCROLL_LATCH_IDLE);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(60.), px(30.)));
+ }
+
+ #[gpui::test]
+ fn test_a_finger_resting_on_the_trackpad_keeps_the_gesture(cx: &mut TestAppContext) {
+ let nested = NestedScrollWindow::open(cx, 20);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Started);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ // The box is under the pointer now, and the finger rests a while.
+ cx.executor()
+ .advance_clock(crate::gestures::SCROLL_LATCH_IDLE * 2);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(90.), px(0.)));
+
+ // Once the finger is lifted, a pause ends the gesture.
+ nested.wheel(cx, OVER_PAGE, 0., TouchPhase::Ended);
+ cx.executor()
+ .advance_clock(crate::gestures::SCROLL_LATCH_IDLE);
+ nested.wheel(cx, OVER_PAGE, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets(), (px(90.), px(30.)));
+ }
+
+ #[gpui::test]
+ fn test_a_sideways_tremor_leaves_a_vertical_gesture_to_the_page(cx: &mut TestAppContext) {
+ // The box's 20 columns scroll 200px sideways.
+ let nested = NestedScrollWindow::open_with(cx, 20, true);
+ nested.wheel_xy(cx, OVER_BOX, 2., 30., TouchPhase::Started);
+ // Still over the box, at y 20 to 120.
+ nested.wheel(cx, OVER_BOX, 30., TouchPhase::Moved);
+ nested.wheel(cx, OVER_BOX, 30., TouchPhase::Moved);
+ assert_eq!(nested.offsets().0, px(90.));
+ }
+
+ #[gpui::test]
+ fn test_a_touch_pan_over_a_nested_box_scrolls_only_the_box(cx: &mut TestAppContext) {
+ let nested = NestedScrollWindow::open(cx, 20);
+ // A pan over the page, above the box.
+ nested.touch(cx, OVER_PAGE, TouchPhase::Started);
+ for y in [30., 20., 10., 0.] {
+ nested.touch(cx, point(px(20.), px(y)), TouchPhase::Moved);
+ }
+ nested.touch(cx, point(px(20.), px(0.)), TouchPhase::Ended);
+ let (page, boxed) = nested.offsets();
+ assert!(page > px(0.), "the pan scrolled the page");
+ assert_eq!(boxed, px(0.));
+
+ // The next pan starts over the box and scrolls only the box.
+ nested.touch(cx, OVER_BOX, TouchPhase::Started);
+ for y in [80., 60., 40.] {
+ nested.touch(cx, point(px(20.), px(y)), TouchPhase::Moved);
+ }
+ let (page_after, boxed) = nested.offsets();
+ assert_eq!(page_after, page);
+ assert!(boxed > px(0.), "the pan scrolled the box");
+ }
}
diff --git a/third-party/gpui-fast/crates/gpui/src/elements/list.rs b/third-party/gpui-fast/crates/gpui/src/elements/list.rs
index 4fe9c171a2..0b9fd2c6aa 100644
--- a/third-party/gpui-fast/crates/gpui/src/elements/list.rs
+++ b/third-party/gpui-fast/crates/gpui/src/elements/list.rs
@@ -7,11 +7,12 @@
//!
//! If all of your elements are the same height, see [`crate::UniformList`] for a simpler API
+use crate::gestures::{ScrollLatch, ScrollTurn};
use crate::{
- AnyElement, App, AvailableSpace, Bounds, ContentMask, DispatchPhase, Edges, Element, EntityId,
- FocusHandle, GlobalElementId, Hitbox, HitboxBehavior, InspectorElementId, IntoElement,
- Overflow, Pixels, Point, ScrollDelta, ScrollWheelEvent, Size, Style, StyleRefinement, Styled,
- Window, point, px, size,
+ AnyElement, App, AvailableSpace, Axis, Bounds, ContentMask, DispatchPhase, Edges, Element,
+ EntityId, FocusHandle, GlobalElementId, Hitbox, HitboxBehavior, InspectorElementId,
+ IntoElement, Overflow, Pixels, Point, ScrollDelta, ScrollWheelEvent, Size, Style,
+ StyleRefinement, Styled, Window, point, px, size,
};
use collections::VecDeque;
use refineable::Refineable as _;
@@ -916,6 +917,9 @@ impl StateInner {
scroll_top.item_ix..cursor.start().count + 1
}
+ /// Scrolls by `delta` from `scroll_top`, the top this frame laid out;
+ /// returns the new top, in pixels from the start, unless the list could
+ /// not scroll.
fn scroll(
&mut self,
scroll_top: &ListOffset,
@@ -924,11 +928,11 @@ impl StateInner {
current_view: EntityId,
window: &mut Window,
cx: &mut App,
- ) {
+ ) -> Option<Pixels> {
// Drop scroll events after a reset, since we can't calculate
// the new logical scroll top without the item heights
if self.reset {
- return;
+ return None;
}
let padding = self.last_padding.unwrap_or_default();
@@ -979,6 +983,7 @@ impl StateInner {
crate::fast::layers::invalidate::note_list_scrolled(window, &self.version, current_view);
cx.notify(current_view);
+ Some(new_scroll_top)
}
pub(crate) fn logical_scroll_top(&self) -> ListOffset {
@@ -1712,18 +1717,41 @@ impl Element for List {
let scroll_top = prepaint.layout.scroll_top;
let hitbox_id = prepaint.hitbox.id;
let mut accumulated_scroll_delta = ScrollDelta::default();
+ // The state's cell stays the same from frame to frame.
+ let owner = Rc::as_ptr(&list_state.0) as *const () as usize;
+ // Each event this frame scrolls from the top it laid out, by the
+ // deltas so far; whether one moved the list is against the last.
+ let mut last_top = list_state.0.borrow().scroll_top(&scroll_top);
window.on_mouse_event(move |event: &ScrollWheelEvent, phase, window, cx| {
if phase == DispatchPhase::Bubble && hitbox_id.should_handle_scroll(window) {
+ // A scroll container inside the list may hold the gesture
+ // (`ScrollLatch`); its listener has run already.
+ let turn = window.scroll_latch.turn(owner);
+ if turn == ScrollTurn::Elsewhere {
+ return;
+ }
accumulated_scroll_delta = accumulated_scroll_delta.coalesce(event.delta);
let pixel_delta = accumulated_scroll_delta.pixel_delta(px(20.));
- list_state.0.borrow_mut().scroll(
+ let top = list_state.0.borrow_mut().scroll(
&scroll_top,
height,
pixel_delta,
current_view,
window,
cx,
- )
+ );
+ let moved = top.is_some_and(|top| top != last_top);
+ if let Some(top) = top {
+ last_top = top;
+ }
+ // It scrolls only vertically, so a sideways gesture is not
+ // its to take.
+ let along = ScrollLatch::axis(event.delta.pixel_delta(px(20.))) == Axis::Vertical;
+ if (moved && along) || turn == ScrollTurn::Held {
+ window
+ .scroll_latch
+ .hold(owner, cx.background_executor().now());
+ }
}
});
@@ -3091,4 +3119,116 @@ mod test {
(so frozen_bottom < live_bottom)"
);
}
+
+ #[gpui::test]
+ fn test_wheel_over_a_box_in_a_list_scrolls_only_the_box(cx: &mut TestAppContext) {
+ use crate::{
+ ParentElement as _, ScrollHandle, StatefulInteractiveElement as _, TouchPhase,
+ };
+
+ let cx = cx.add_empty_window();
+ // Five rows of 60px in a list 100px tall, all measured; the first is
+ // a box that scrolls 140px.
+ let state = ListState::new(5, crate::ListAlignment::Top, px(300.));
+ let boxed = ScrollHandle::new();
+
+ struct TestView(ListState, ScrollHandle);
+ impl Render for TestView {
+ fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
+ let boxed = self.1.clone();
+ list(self.0.clone(), move |ix, _, _| {
+ if ix == 0 {
+ div()
+ .id("box")
+ .h(px(60.))
+ .w_full()
+ .overflow_y_scroll()
+ .track_scroll(&boxed)
+ .children((0..10).map(|_| div().h(px(20.)).w_full().flex_none()))
+ .into_any()
+ } else {
+ div().h(px(60.)).w_full().into_any()
+ }
+ })
+ .w_full()
+ .h_full()
+ }
+ }
+
+ let view = cx.update(|_, cx| cx.new(|_| TestView(state.clone(), boxed.clone())));
+ let mut wheel = |dy: f32, touch_phase| {
+ cx.draw(point(px(0.), px(0.)), size(px(100.), px(100.)), |_, _| {
+ view.clone().into_any_element()
+ });
+ cx.simulate_event(ScrollWheelEvent {
+ position: point(px(10.), px(10.)),
+ delta: ScrollDelta::Pixels(point(px(0.), px(-dy))),
+ touch_phase,
+ ..Default::default()
+ });
+ };
+ let list_top = |state: &ListState| {
+ let top = state.logical_scroll_top();
+ px(60.) * top.item_ix as f32 + top.offset_in_item
+ };
+
+ wheel(30., TouchPhase::Started);
+ wheel(200., TouchPhase::Moved);
+ assert_eq!((list_top(&state), -boxed.offset().y), (px(0.), px(140.)));
+
+ // The next gesture finds the box at its end and scrolls the list.
+ wheel(30., TouchPhase::Started);
+ assert_eq!((list_top(&state), -boxed.offset().y), (px(30.), px(140.)));
+ wheel(-20., TouchPhase::Moved);
+ assert_eq!((list_top(&state), -boxed.offset().y), (px(10.), px(140.)));
+ }
+
+ #[gpui::test]
+ fn test_a_sideways_gesture_over_a_list_is_not_the_lists(cx: &mut TestAppContext) {
+ use crate::{
+ InteractiveElement as _, ParentElement as _, ScrollHandle,
+ StatefulInteractiveElement as _, TouchPhase,
+ };
+
+ let cx = cx.add_empty_window();
+ // Five rows of 60px in a list 100px tall and 300px wide, in a strip
+ // 100px wide that scrolls it 200px sideways.
+ let state = ListState::new(5, crate::ListAlignment::Top, px(300.));
+ let strip = ScrollHandle::new();
+
+ struct TestView(ListState, ScrollHandle);
+ impl Render for TestView {
+ fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
+ div()
+ .id("strip")
+ .flex()
+ .size_full()
+ .overflow_x_scroll()
+ .track_scroll(&self.1)
+ .child(
+ list(self.0.clone(), |_, _, _| {
+ div().h(px(60.)).w_full().into_any()
+ })
+ .w(px(300.))
+ .h_full()
+ .flex_none(),
+ )
+ }
+ }
+
+ let view = cx.update(|_, cx| cx.new(|_| TestView(state.clone(), strip.clone())));
+ for (dx, dy, touch_phase) in [(30., 2., TouchPhase::Started), (30., 0., TouchPhase::Moved)]
+ {
+ cx.draw(point(px(0.), px(0.)), size(px(100.), px(100.)), |_, _| {
+ view.clone().into_any_element()
+ });
+ cx.simulate_event(ScrollWheelEvent {
+ position: point(px(10.), px(10.)),
+ delta: ScrollDelta::Pixels(point(px(-dx), px(-dy))),
+ touch_phase,
+ ..Default::default()
+ });
+ }
+ assert_eq!(strip.offset().x, px(-60.));
+ }
}
diff --git a/third-party/gpui-fast/crates/gpui/src/gestures.rs b/third-party/gpui-fast/crates/gpui/src/gestures.rs
index 38a914ff02..653437e453 100644
--- a/third-party/gpui-fast/crates/gpui/src/gestures.rs
+++ b/third-party/gpui-fast/crates/gpui/src/gestures.rs
@@ -107,6 +107,104 @@ impl OngoingScroll {
}
}
+/// How long a scroll container keeps a wheel gesture without taking an event
+/// of it, once no finger is on the trackpad.
+pub(crate) const SCROLL_LATCH_IDLE: Duration = Duration::from_millis(300);
+
+/// Which scroll container a wheel gesture belongs to, so nested containers
+/// do not all move with it.
+///
+/// The innermost container under the pointer that moves along the gesture's
+/// axis takes the gesture, and keeps it until the gesture ends: the
+/// containers around it leave its events alone, and so do containers the
+/// scroll brings under the pointer. It keeps it at its end too, rather than
+/// passing the rest of a fling to the container around it. A container that
+/// cannot move lets the event pass outward, so a box at its end hands the
+/// next gesture to the page.
+///
+/// A gesture ends with the next [`TouchPhase::Started`], where the platform
+/// reports phases; when an event comes from another position, as the
+/// pointer moved; or once the container holding it has taken none of its
+/// events for [`SCROLL_LATCH_IDLE`], as a mouse wheel's ticks come without
+/// phases. A gesture that began with [`TouchPhase::Started`] does not end
+/// that way before its [`TouchPhase::Ended`], as a finger can rest on the
+/// trackpad.
+///
+/// Containers take their turns in the bubble phase, innermost first, and
+/// leave the event to propagate: other listeners, such as a scrollbar's,
+/// still see it. A container that scrolls on one axis with the wheel's other
+/// axis, as GPUI lets one do, takes no turn, and moves with the gesture as
+/// before.
+#[derive(Clone, Copy, Debug, Default)]
+pub(crate) struct ScrollLatch {
+ /// The container holding the gesture, and when it last took an event.
+ holder: Option<(usize, Instant)>,
+ /// Where the last wheel event was.
+ position: Option<Point<Pixels>>,
+ /// Whether the gesture began with [`TouchPhase::Started`] and has not
+ /// had its [`TouchPhase::Ended`].
+ touching: bool,
+}
+
+/// What a scroll container may do with a wheel event, from [`ScrollLatch::turn`].
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(crate) enum ScrollTurn {
+ /// No container holds the gesture: scroll, and take it if that moved
+ /// this container along the gesture's axis.
+ Free,
+ /// This container holds the gesture: scroll, and take the event even if
+ /// that did not move.
+ Held,
+ /// Another container holds the gesture: leave the event to it.
+ Elsewhere,
+}
+
+impl ScrollLatch {
+ /// Called as a wheel event of `phase` at `position` begins to be
+ /// dispatched at `now`, before any container sees it: ends the gesture
+ /// the event does not belong to.
+ pub(crate) fn begin(&mut self, phase: TouchPhase, position: Point<Pixels>, now: Instant) {
+ let idle = !self.touching
+ && self
+ .holder
+ .is_some_and(|(_, at)| now.duration_since(at) >= SCROLL_LATCH_IDLE);
+ let pointer_moved = self
+ .position
+ .replace(position)
+ .is_some_and(|last| last != position);
+ if phase == TouchPhase::Started || idle || pointer_moved {
+ self.holder = None;
+ self.touching = false;
+ }
+ match phase {
+ TouchPhase::Started => self.touching = true,
+ TouchPhase::Ended | TouchPhase::Cancelled => self.touching = false,
+ TouchPhase::Moved => {}
+ }
+ }
+
+ /// The axis a wheel event moves along: a container takes the gesture
+ /// only by moving along it, so a diagonal tremor does not give a
+ /// vertical gesture to a container that scrolls sideways.
+ pub(crate) fn axis(delta: Point<Pixels>) -> Axis {
+ dominant_axis(delta)
+ }
+
+ /// What the container `owner` may do with the event being dispatched.
+ pub(crate) fn turn(&self, owner: usize) -> ScrollTurn {
+ match self.holder {
+ None => ScrollTurn::Free,
+ Some((holder, _)) if holder == owner => ScrollTurn::Held,
+ Some(_) => ScrollTurn::Elsewhere,
+ }
+ }
+
+ /// Notes that `owner` took an event of the gesture at `now`.
+ pub(crate) fn hold(&mut self, owner: usize, now: Instant) {
+ self.holder = Some((owner, now));
+ }
+}
+
/// Feel constants consumed by gesture recognizers. Provided on a best-effort
/// basis, depending on each platform's support, defaulting to GPUI's own
/// (iOS flavored) values
diff --git a/third-party/gpui-fast/crates/gpui/src/window.rs b/third-party/gpui-fast/crates/gpui/src/window.rs
index 5e5c15354b..a7d1c2ddfc 100644
--- a/third-party/gpui-fast/crates/gpui/src/window.rs
+++ b/third-party/gpui-fast/crates/gpui/src/window.rs
@@ -1447,6 +1447,8 @@ pub struct Window {
default_prevented: bool,
pub(crate) mouse_position: Point<Pixels>,
pub(crate) mouse_hit_test: HitTest,
+ /// The scroll container the current wheel gesture belongs to.
+ pub(crate) scroll_latch: crate::gestures::ScrollLatch,
modifiers: Modifiers,
capslock: Capslock,
scale_factor: f32,
@@ -2367,6 +2369,7 @@ impl Window {
default_prevented: true,
mouse_position,
mouse_hit_test: HitTest::default(),
+ scroll_latch: Default::default(),
modifiers,
capslock,
scale_factor,
@@ -6349,6 +6352,13 @@ impl Window {
crate::fast::layers::input::before_dispatch(self, cx, &event);
}
+ if let PlatformInput::ScrollWheel(wheel) = &event {
+ self.scroll_latch.begin(
+ wheel.touch_phase,
+ wheel.position,
+ cx.background_executor().now(),
+ );
+ }
if let Some(any_mouse_event) = event.mouse_event() {
self.dispatch_mouse_event(any_mouse_event, cx);
} else if let Some(any_key_event) = event.keyboard_event() {
@@ -6476,6 +6486,11 @@ impl Window {
match gesture {
RecognizedTouchGesture::Scroll(scroll_wheel) => {
self.mouse_position = scroll_wheel.position;
+ self.scroll_latch.begin(
+ scroll_wheel.touch_phase,
+ scroll_wheel.position,
+ cx.background_executor().now(),
+ );
cx.propagate_event = true;
self.dispatch_mouse_event(&scroll_wheel, cx);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org