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

+40 -1
View File
@@ -195,7 +195,10 @@ impl Desk {
#[cfg(test)]
mod tests {
use ely_gpui_component::documents::DocumentLook;
use gpui::{Entity, TestAppContext, VisualTestContext, rems};
use gpui::{
Entity, Modifiers, ScrollDelta, ScrollWheelEvent, TestAppContext, VisualTestContext,
point, rems,
};
use crate::desk::{
Desk,
@@ -275,4 +278,40 @@ mod tests {
(super::Width::Wide, super::Font::Serif, 120)
);
}
#[gpui::test]
fn ctrl_and_the_wheel_size_the_text(cx: &mut TestAppContext) {
let (data, files) = (
tempfile::tempdir().expect("data"),
tempfile::tempdir().expect("files"),
);
let path = files.path().join("a.md");
std::fs::write(&path, "a
").expect("a file");
let (desk, cx) = start(cx, data.path());
open(&desk, &path, cx);
let focus = desk.read_with(cx, |desk, _| desk.core.focus.clone());
cx.update(|window, cx| window.focus(&focus, cx));
let at = cx.update(|window, _| window.viewport_size()).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() },
};
cx.simulate_event(wheel(other, 3.0));
cx.run_until_parked();
assert_eq!(document_look(&desk, cx).scale, 1.0, "only Ctrl, or Cmd on macOS");
cx.simulate_event(wheel(Modifiers::secondary_key(), 3.0));
cx.run_until_parked();
assert_eq!(document_look(&desk, cx).scale, 1.1, "a notch is one step");
cx.simulate_event(wheel(Modifiers::secondary_key(), -1.0));
cx.simulate_event(wheel(Modifiers::secondary_key(), -1.0));
cx.run_until_parked();
assert_eq!(document_look(&desk, cx).scale, 0.9);
}
}
+17 -1
View File
@@ -79,6 +79,8 @@ pub struct MarkView {
pub(crate) folder: Option<PathBuf>,
/// The mode first took input (PERF-07).
pub(crate) shown: bool,
/// Trackpad pixels toward the next size step.
wheel: f32,
pub focus: FocusHandle,
}
@@ -123,6 +125,7 @@ impl MarkView {
mode,
folder: None,
shown: false,
wheel: 0.0,
focus,
}
}
@@ -301,11 +304,24 @@ impl MarkView {
}
impl Render for MarkView {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
// Ctrl and the wheel size text, as Ctrl+= does.
let zoom = ely_ui::wheel::zoom_layer(move |event, window, cx| {
let steps = view.update(cx, |view, _| ely_ui::wheel::steps(event, &mut view.wheel));
for _ in 0..steps.unsigned_abs() {
match steps > 0 {
true => window.dispatch_action(Box::new(crate::look::Larger), cx),
false => window.dispatch_action(Box::new(crate::look::Smaller), cx),
}
}
});
div()
.relative()
.size_full()
.track_focus(&self.focus)
.child(self.document.clone())
.child(zoom)
}
}