R3.2: Ctrl+wheel zooms one step per notch; version 0.1.4 [skip ci]

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-12 23:15:47 -04:00
1 parent c1880288a5
commit ee1b8ad375
13 files changed
+274 -37

No files matched your search

+5 -2
View File
@@ -198,7 +198,7 @@ impl PdfView {
})
.collect();
let this = cx.entity();
let (down, moved, up) = (this.clone(), this.clone(), this.clone());
let (down, moved, up, wheeled) = (this.clone(), this.clone(), this.clone(), this.clone());
let pages = div()
.id("pdf-pages")
.size_full()
@@ -249,7 +249,10 @@ impl PdfView {
.top_0()
.left_0()
.size_full();
div().relative().size_full().child(pages).child(measure).into_any_element()
let zoom = ely_ui::wheel::zoom_layer(move |event, _, cx| {
wheeled.update(cx, |view, cx| view.wheel_zoom(event, cx))
});
div().relative().size_full().child(pages).child(measure).child(zoom).into_any_element()
}
/// Asks for the first missing tile, one at a time.
+32 -1
View File
@@ -1,7 +1,7 @@
//! Password prompts, zoomed pairs, jumps across (C11.1).
use ely_office::{Dialog, Dialogs as _, Tabs as _};
use gpui::{Entity, TestAppContext, VisualTestContext, point, px};
use gpui::{Entity, Modifiers, ScrollDelta, ScrollWheelEvent, TestAppContext, VisualTestContext, point, px};
use super::{file, frames, settle, shown, windowed};
use crate::layout::{Mode, Zoom};
@@ -113,3 +113,34 @@ fn a_jump_to_the_right_page_brings_it_across() {
});
assert!(x >= left && x < left + wide, "page at {x}, view {left}..{}", left + wide);
}
#[test]
fn ctrl_and_a_wheel_notch_step_the_zoom_once() {
let dir = tempfile::tempdir().expect("a temp dir");
let mut cx = TestAppContext::single();
let pages: &[(f32, f32, &[&str])] = &[(612.0, 792.0, &["one"]), (612.0, 792.0, &["two"]), (612.0, 792.0, &["three"])];
let (viewer, cx) = windowed(&mut cx, dir.path(), &[file(dir.path(), "three.pdf", pages)], true);
let view = shown(cx, &viewer);
settle(cx, |app| view.read(app).room.size.width > px(100.0));
cx.update(|_, app| view.update(app, |view, cx| view.change(|view, _| view.zoom = Zoom::Scale(1.0), cx)));
frames(cx);
let at = cx.update(|_, app| view.read(app).room.center());
let wheel = |modifiers, y| ScrollWheelEvent { position: at, delta: ScrollDelta::Lines(point(0.0, y)), modifiers, ..Default::default() };
let other = match cfg!(target_os = "macos") {
true => Modifiers { control: true, ..Default::default() },
false => Modifiers { platform: true, ..Default::default() },
};
let read = |cx: &mut VisualTestContext| cx.update(|_, app| (view.read(app).zoom, view.read(app).scroll.offset().y));
cx.simulate_event(wheel(other, -3.0));
frames(cx);
let (zoom, scrolled) = read(cx);
assert_eq!(zoom, Zoom::Scale(1.0), "only Ctrl, or Cmd on macOS");
assert!(scrolled < px(0.0), "a plain wheel scrolls");
cx.simulate_event(wheel(Modifiers::secondary_key(), 3.0));
frames(cx);
assert_eq!(read(cx).0, Zoom::Scale(crate::keys::stepped(1.0, true)), "a notch is one step");
cx.simulate_event(wheel(Modifiers::secondary_key(), -3.0));
cx.simulate_event(wheel(Modifiers::secondary_key(), -3.0));
frames(cx);
assert_eq!(read(cx).0, Zoom::Scale(crate::keys::stepped(1.0, false)));
}
+11
View File
@@ -70,6 +70,8 @@ pub struct PdfView {
pub painting: bool,
/// The view's size and place, as last painted.
pub room: gpui::Bounds<gpui::Pixels>,
/// Trackpad pixels toward the next zoom step.
pub wheel: f32,
pub focus: FocusHandle,
/// Counts edits; replies from before one are dropped.
pub version: u64,
@@ -199,6 +201,7 @@ impl PdfView {
go_to: None,
painting: false,
room: gpui::Bounds::default(),
wheel: 0.0,
focus: cx.focus_handle(),
version: 0,
edited: 0,
@@ -354,6 +357,14 @@ impl PdfView {
self.show(self.current, 0.0, cx);
}
/// Ctrl (Cmd on macOS) and the wheel step the zoom.
pub fn wheel_zoom(&mut self, event: &gpui::ScrollWheelEvent, cx: &mut Context<Self>) {
let steps = ely_ui::wheel::steps(event, &mut self.wheel);
for _ in 0..steps.unsigned_abs() {
self.change(|view, now| view.zoom = Zoom::Scale(crate::keys::stepped(now, steps > 0)), cx);
}
}
/// Moves `by` pages; continuous views scroll there.
pub fn turn(&mut self, by: isize, cx: &mut Context<Self>) {
let last = self.sizes.len().saturating_sub(1) as isize;