DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge canvas-scrollbars: UI: document views have scrollbars, and Alt pans while editing text
aiongg54520e11e850
diff --cc crates/ui-egui/src/canvas.rsindex 6ddc52a36,56c482195..e62ba9fd5--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@@ -1646,9 -1356,109 +1661,111 @@@ pub(crate) fn fmt_tick(v: f64) -> Strinif (v - r).abs() < 1e-6 { format!("{}", r as i64) } else { format!("{v:.1}") }}+ /// Move the view's content by a screen-space distance `d` (rotated views move in screen axes).+ fn pan(app: &mut DesignApp, xf: &Xf, d: egui::Vec2) {+ let d = xf.unrotate_delta(d);+ if let Some(v) = app.view_mut() {+ v.origin = Point::new(v.origin.x - d.x as f64 / v.zoom, v.origin.y - d.y as f64 / v.zoom);+ }+ }++ /// A scrollbar thumb on a track `track` pixels long, for `visible` (the view) within `content`+ /// (the pasteboard), both spans along the bar's axis in screen pixels: the thumb's start and+ /// length on the track, and the content pixels one thumb pixel moves (0 when nothing scrolls).+ fn thumb_span(track: f32, content: (f32, f32), visible: (f32, f32)) -> (f32, f32, f32) {+ let track = track.max(0.0);+ let (lo, hi) = (content.0.min(visible.0), content.1.max(visible.1));+ let (total, shown) = (hi - lo, visible.1 - visible.0);+ let scrollable = total - shown;+ if !total.is_finite() || !shown.is_finite() || total <= 0.0 || scrollable <= 0.0 {+ return (0.0, track, 0.0);+ }+ let len = (track * shown / total).max(MIN_THUMB.min(track));+ let free = track - len;+ if free <= 0.0 {+ return (0.0, track, 0.0);+ }+ ((visible.0 - lo) / scrollable * free, len, scrollable / free)+ }++ /// The track and thumb of the vertical (or horizontal) scrollbar of the view `screen` inside+ /// `outer`, and the content pixels per thumb pixel.+ fn scrollbar_rects(outer: Rect, screen: Rect, content: Rect, vertical: bool) -> (Rect, Rect, f32) {+ if vertical {+ let track = Rect::from_min_max(pos2(outer.max.x - SCROLLBAR, screen.min.y), pos2(outer.max.x, screen.max.y));+ let (start, len, k) = thumb_span(track.height(), (content.min.y, content.max.y), (screen.min.y, screen.max.y));+ (track, Rect::from_min_size(pos2(track.min.x, track.min.y + start), vec2(SCROLLBAR, len)), k)+ } else {+ let track = Rect::from_min_max(pos2(screen.min.x, outer.max.y - SCROLLBAR), pos2(screen.max.x, outer.max.y));+ let (start, len, k) = thumb_span(track.width(), (content.min.x, content.max.x), (screen.min.x, screen.max.x));+ (track, Rect::from_min_size(pos2(track.min.x + start, track.min.y), vec2(len, SCROLLBAR)), k)+ }+ }++ /// The view's scrollbars, on the right and bottom edges of `outer`: they span the pasteboard;+ /// dragging a thumb pans, clicking the track pages by one view.+ fn scrollbars(app: &mut DesignApp, ui: &mut egui::Ui, outer: Rect, screen: Rect, rect: Rect, t: &Tokens) {+ let content = |app: &DesignApp| {+ let st = app.session.active()?;+ let v = app.view()?;+ let xf = Xf::new(rect, v);+ Some((xf, xf.rect(CanvasLayout::new(&st.doc, st.editing_parents).pasteboard)))+ };+ let Some((xf, cb)) = content(app) else { return };+ let press = ui.input(|i| i.pointer.press_origin());+ let mut hot = [false; 2];+ for (n, vertical) in [true, false].into_iter().enumerate() {+ let (track, thumb, k) = scrollbar_rects(outer, screen, cb, vertical);+ let id = egui::Id::new(("canvas_scrollbar", app.pane, vertical));+ let resp = ui.interact(track, id, Sense::click_and_drag());+ let grab_id = id.with("grab");+ if resp.drag_started() {+ let on_thumb = press.is_some_and(|p| thumb.contains(p));+ ui.data_mut(|d| d.insert_temp(grab_id, on_thumb));+ }+ let grabbed = resp.dragged() && ui.data(|d| d.get_temp::<bool>(grab_id)).unwrap_or(false);+ if !resp.dragged() {+ ui.data_mut(|d| d.remove::<bool>(grab_id));+ }+ let along = |p: egui::Vec2| if vertical { p.y } else { p.x };+ let page = along(screen.size());+ let mut moved = 0.0;+ if grabbed {+ moved = -along(resp.drag_delta()) * k;+ } else if resp.clicked()+ && let Some(p) = resp.interact_pointer_pos()+ {+ let (p, a, b) = if vertical { (p.y, thumb.min.y, thumb.max.y) } else { (p.x, thumb.min.x, thumb.max.x) };+ if p < a {+ moved = page;+ } else if p > b {+ moved = -page;+ }+ }+ if moved != 0.0 && moved.is_finite() {+ pan(app, &xf, if vertical { vec2(0.0, moved) } else { vec2(moved, 0.0) });+ }+ if let Some(slot) = hot.get_mut(n) {+ *slot = grabbed || resp.hovered();+ }+ }+ // Painted from the view as it is after this frame's input.+ let Some((_, cb)) = content(app) else { return };+ let painter = ui.painter_at(outer);+ let right = Rect::from_min_max(pos2(outer.max.x - SCROLLBAR, outer.min.y), outer.max);+ let bottom = Rect::from_min_max(pos2(outer.min.x, outer.max.y - SCROLLBAR), outer.max);+ painter.rect_filled(right, 0.0, t.panel_darker);+ painter.rect_filled(bottom, 0.0, t.panel_darker);+ for (n, vertical) in [true, false].into_iter().enumerate() {+ let (_, thumb, _) = scrollbar_rects(outer, screen, cb, vertical);+ let alpha = if hot.get(n).copied().unwrap_or(false) { 0.6 } else { 0.35 };+ painter.rect_filled(thumb.shrink(2.0), SCROLLBAR / 2.0 - 2.0, t.text.gamma_multiply(alpha));+ }+ }+fn handle_input(app: &mut DesignApp, ui: &mut egui::Ui, resp: &egui::Response, rect: Rect) {+ // While a context menu is open (in either pane), the click that closes it and the keys go to the menu.+ let menu_open = context_menu_open(ui.ctx());let Some(v) = app.view().copied() else { return };let xf = Xf::new(rect, &v);let wants_text = app.session.wants_text();@@@ -1680,11 -1490,23 +1797,26 @@@}return;}+ // Editing text (Space types a space): Alt held at the press gives the Hand tool until the+ // button is released, and the caret stays. Alt pressed later in a text drag copies the text.+ let alt_hand_id = egui::Id::new(("canvas_alt_hand", app.pane));+ let mut alt_hand: bool = ui.data(|d| d.get_temp(alt_hand_id)).unwrap_or(false);+ let (press, alt, primary_down) = ui.input(|i| (i.pointer.primary_pressed(), i.modifiers.alt, i.pointer.primary_down()));- if press && alt && wants_text && !tool_drag && resp.hovered() {++ if press && alt && wants_text && !tool_drag && !menu_open && resp.hovered() {+ alt_hand = true;+ }+ if alt_hand {+ if resp.dragged() {+ pan(app, &xf, resp.drag_delta());+ }+ ui.data_mut(|d| d.insert_temp(alt_hand_id, primary_down));+ return;+ }- // Ruler guides need the rulers (hidden while the view is rotated).- if !space && xf.rot == 0 && guide_drag(app, ui, resp, rect, &xf) {+ // The zero point and ruler guides need the rulers (hidden while the view is rotated).+ if !space && !menu_open && xf.rot == 0 && zero_point_drag(app, ui, resp, rect, &xf) {+ return;+ }+ if !space && !menu_open && xf.rot == 0 && guide_drag(app, ui, resp, rect, &xf) {return;}let m = ui.input(|i| mods(i, space));@@@ -2725,240 -1937,143 +2857,379 @@@ mod testsright_click(&mut h, pos2(rect.center().x, rect.min.y - RULER / 2.0));assert!(h.query_by_label(" Points").is_none());}++ /// One frame of the whole app with `events`; returns what it asks of the system IME.+ fn ime_frame(app: &mut DesignApp, ctx: &egui::Context, events: Vec<egui::Event>) -> Option<egui::output::IMEOutput> {+ let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1400.0, 900.0))), events, ..Default::default() };+ let mut out = ctx.run_ui(raw, |ui| {+ app.logic(ui.ctx());+ app.ui(ui);+ });+ out.textures_delta.clear();+ out.platform_output.ime+ }++ /// An edit patches the canvas texture in place only while that texture is at full resolution:+ /// past the GPU's texture limit `upload` shrinks it, and a full-resolution patch written into+ /// it is a renderer validation error.+ #[test]+ fn edits_patch_the_canvas_only_at_full_resolution() {+ for (max_side, patches) in [(None, true), (Some(1024), false)] {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ let ctx = egui::Context::default();+ let frame = |app: &mut DesignApp| {+ // Wider than the limit (egui's font atlas needs at least 1024).+ let mut raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1900.0, 900.0))), ..Default::default() };+ if let Some(m) = max_side {+ raw.max_texture_side = Some(m);+ }+ let mut out = ctx.run_ui(raw, |ui| {+ app.logic(ui.ctx());+ app.ui(ui);+ });+ out.textures_delta.clear();+ };+ app.run("file.new", json!({})).unwrap();+ for _ in 0..3 {+ frame(&mut app);+ }+ app.run("frame.create", json!({"rect": [36, 36, 60, 60]})).unwrap();+ frame(&mut app);+ let size = app.canvas.texture.as_ref().unwrap().size();+ assert!(max_side.is_none_or(|m| size[0] <= m && size[1] <= m), "{size:?}");+ assert_eq!(app.canvas.patches > 0, patches, "limit {max_side:?}");+ }+ }++ /// The Type tool's caret at the end of a new text frame holding `text`, the app's first frames+ /// drawn; returns the story id.+ fn typing_app(app: &mut DesignApp, ctx: &egui::Context, text: &str) -> Value {+ app.run("file.new", json!({})).unwrap();+ let f = app.session.execute("frame.create", &json!({"rect": [36, 36, 300, 200], "content": "text", "text": text})).unwrap();+ let sid = f["story"].clone();+ app.session.execute("text.select", &json!({"story": sid, "anchor": text.len(), "focus": text.len()})).unwrap();+ app.select_tool("type");+ for _ in 0..4 {+ ime_frame(app, ctx, vec![]);+ }+ sid+ }++ fn story_text(app: &mut DesignApp, sid: &Value) -> String {+ app.session.execute("story.get", &json!({"story": sid})).unwrap()["text"].as_str().unwrap().to_string()+ }++ /// Spread point `p` on screen.+ fn on_screen(app: &DesignApp, p: Point) -> Pos2 {+ let st = app.session.active().unwrap();+ let c = CanvasLayout::new(&st.doc, st.editing_parents).to_canvas(SpreadRef::Doc(0), p);+ Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()).to_screen(c)+ }++ fn preedit(t: &str, c: usize) -> egui::Event {+ egui::Event::Ime(egui::ImeEvent::Preedit { text: t.into(), active_range_chars: Some(c..c) })+ }++ #[test]+ #[allow(deprecated)] // `ImeEvent::Enabled` / `Disabled`: egui no longer sends them, other integrations may.+ fn ime_events_compose_in_the_story_with_the_candidate_window_at_the_caret() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ let ctx = egui::Context::default();+ let sid = typing_app(&mut app, &ctx, "曲:");+ // At a text caret the IME is allowed, its window on the caret as the canvas draws it.+ let ime = ime_frame(&mut app, &ctx, vec![]).expect("IME allowed at a text caret");+ let (top, bottom) = {+ let st = app.session.active().unwrap();+ let cs = app.session.cache.get(&st.doc, designcraft_doc::StoryId(sid.as_u64().unwrap()), None);+ let (fi, x, bl, asc, desc) = compose::caret(&cs, "曲:".len()).unwrap();+ let fid = cs.frames[fi].frame;+ let (a, _) = item_canvas_xf(&st.doc, &CanvasLayout::new(&st.doc, st.editing_parents), fid).unwrap();+ let m = a * st.doc.text_xf(st.doc.item(fid).unwrap());+ let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());+ (xf.to_screen(m * Point::new(x, bl - asc)), xf.to_screen(m * Point::new(x, bl + desc)))+ };+ assert!(ime.rect.expand(1.0).contains(top) && ime.rect.expand(1.0).contains(bottom), "{:?} vs {top:?}–{bottom:?}", ime.rect);+ assert_eq!(ime.cursor_rect, ime.rect);+ assert!(!ime.should_interrupt_composition);+ assert!(app.canvas_ime(), "the web build keeps whole words typed at the caret");+ // "ni" → に → 日, with the events winit sends.+ ime_frame(&mut app, &ctx, vec![egui::Event::Ime(egui::ImeEvent::Enabled), preedit("ni", 2)]);+ assert_eq!(story_text(&mut app, &sid), "曲:ni", "marked text shows in place");+ assert!(app.session.tool_composing());+ // Keys, plain text, the clipboard and Undo (the native menu's ⌘Z) wait for the IME.+ let steps = app.session.doc().unwrap().history.undo.len();+ let key = |key, pressed| egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers: Default::default() };+ ime_frame(+ &mut app,+ &ctx,+ vec![key(egui::Key::Backspace, true), key(egui::Key::Backspace, false), egui::Event::Text("x".into()), egui::Event::Paste("y".into())],+ );+ crate::menus::activate(&mut app, "edit.undo", &Value::Null);+ assert!(!crate::menus::enabled(&app, "edit.undo"));+ assert_eq!(story_text(&mut app, &sid), "曲:ni");+ let ime2 = ime_frame(&mut app, &ctx, vec![preedit("に", 1)]).expect("IME allowed while composing");+ assert_eq!(story_text(&mut app, &sid), "曲:に");+ assert!(ime2.rect.center().x > ime.rect.center().x, "the window follows the IME's cursor: {:?} {:?}", ime2.rect, ime.rect);+ ime_frame(&mut app, &ctx, vec![egui::Event::Ime(egui::ImeEvent::Commit("日".into())), egui::Event::Ime(egui::ImeEvent::Disabled)]);+ assert_eq!(story_text(&mut app, &sid), "曲:日");+ assert!(!app.session.tool_composing());+ assert_eq!(app.session.doc().unwrap().history.undo.len(), steps + 1, "the commit is one undo step");+ assert_eq!(app.session.journal.last(), Some(&("text.insert".to_string(), json!({"text": "日"}))));+ // After the commit, typing and Undo work again.+ ime_frame(&mut app, &ctx, vec![egui::Event::Text("!".into())]);+ assert_eq!(story_text(&mut app, &sid), "曲:日!");+ crate::menus::activate(&mut app, "edit.undo", &Value::Null);+ crate::menus::activate(&mut app, "edit.undo", &Value::Null);+ assert_eq!(story_text(&mut app, &sid), "曲:");+ // Without a text caret the IME is off: single-key tool shortcuts keep working.+ app.select_tool("selection");+ assert!(ime_frame(&mut app, &ctx, vec![]).is_none());+ assert!(!app.canvas_ime());+ }++ /// Both panes of a split window see the same keyboard events: only the pane last clicked+ /// types them.+ #[test]+ fn a_split_window_types_once() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ let ctx = egui::Context::default();+ let sid = typing_app(&mut app, &ctx, "ab");+ app.run("window.split", json!({"on": true})).unwrap();+ for _ in 0..3 {+ ime_frame(&mut app, &ctx, vec![]);+ }+ assert!(app.other_pane.as_ref().and_then(|o| o.1).is_some(), "both panes are drawn");+ ime_frame(&mut app, &ctx, vec![egui::Event::Text("c".into())]);+ assert_eq!(story_text(&mut app, &sid), "abc");+ let key = |pressed| egui::Event::Key { key: egui::Key::Backspace, physical_key: None, pressed, repeat: false, modifiers: Default::default() };+ ime_frame(&mut app, &ctx, vec![key(true), key(false)]);+ assert_eq!(story_text(&mut app, &sid), "ab");+ ime_frame(&mut app, &ctx, vec![egui::Event::Paste("de".into())]);+ assert_eq!(story_text(&mut app, &sid), "abde");+ ime_frame(&mut app, &ctx, vec![preedit("に", 1)]);+ assert_eq!(story_text(&mut app, &sid), "abdeに");+ ime_frame(&mut app, &ctx, vec![egui::Event::Ime(egui::ImeEvent::Commit("日".into()))]);+ assert_eq!(story_text(&mut app, &sid), "abde日");+ }++ #[test]+ fn clicking_away_mid_composition_keeps_the_text_and_interrupts_the_ime() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ let ctx = egui::Context::default();+ let sid = typing_app(&mut app, &ctx, "");+ ime_frame(&mut app, &ctx, vec![preedit("しょうこ", 4)]);+ assert!(app.session.tool_composing());+ // A click in the frame (macOS and Windows send nothing for it): the marked text stays as+ // typed and the IME is told to drop its composition, once.+ let p = on_screen(&app, Point::new(150.0, 120.0));+ let press = |pressed| egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };+ let ime = ime_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(p), press(true)]).expect("still at a text caret");+ assert!(ime.should_interrupt_composition);+ ime_frame(&mut app, &ctx, vec![press(false)]);+ assert!(!app.session.tool_composing());+ assert_eq!(story_text(&mut app, &sid), "しょうこ");+ assert!(app.take_ime_discard(), "the host tells the system IME to drop its marked text");+ assert!(!ime_frame(&mut app, &ctx, vec![]).expect("still at a text caret").should_interrupt_composition);+ assert!(!app.take_ime_discard());+ // A bare line break from the IME confirms a composition: the marked text, no new paragraph.+ ime_frame(&mut app, &ctx, vec![preedit("がく", 2)]);+ ime_frame(&mut app, &ctx, vec![egui::Event::Ime(egui::ImeEvent::Commit("\n".into()))]);+ assert!(!app.session.tool_composing());+ let typed = story_text(&mut app, &sid);+ assert!(typed.contains("がく") && typed.contains("しょうこ") && !typed.contains('\n'), "{typed:?}");+ }+}++#[cfg(test)]+mod pencil_preview_tests {+ use egui::{Pos2, pos2, vec2};++ /// Lines painted in `color` (egui paths) and the points they pass through.+ fn lines_in(h: &egui_kittest::Harness<'static, crate::test_window::Window>, color: egui::Color32) -> Vec<Vec<Pos2>> {+ fn walk(s: &egui::Shape, color: egui::Color32, out: &mut Vec<Vec<Pos2>>) {+ match s {+ egui::Shape::Path(p) if p.stroke.color == egui::epaint::ColorMode::Solid(color) && p.points.len() >= 2 => out.push(p.points.clone()),+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, color, out)),+ _ => {}+ }+ }+ let mut out = vec![];+ h.output().shapes.iter().for_each(|s| walk(&s.shape, color, &mut out));+ out+ }++ #[test]+ fn the_pencil_stroke_shows_while_drawing() {+ let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", serde_json::json!({})).unwrap();+ app.run("tool.select", serde_json::json!({"tool": "pencil"})).unwrap();+ let mut h = crate::test_window::open(app, vec2(1400.0, 900.0));+ let doc = &h.state().app.session.doc().unwrap().doc;+ let layer = doc.layers[0].color;+ let color = egui::Color32::from_rgb(layer[0], layer[1], layer[2]);+ let items = |h: &egui_kittest::Harness<'static, crate::test_window::Window>| h.state().app.session.doc().unwrap().doc.spreads[0].items.len();+ let before = items(&h);+ // Press on the page and drag, without letting go.+ let start = pos2(520.0, 380.0);+ h.hover_at(start);+ h.drag_at(start);+ h.run_steps(2);+ let path: Vec<Pos2> = (1..=12).map(|i| start + vec2(i as f32 * 12.0, (i as f32 * 0.6).sin() * 30.0)).collect();+ for p in &path {+ h.hover_at(*p);+ h.run_steps(1);+ }+ let drawn = lines_in(&h, color);+ let stroke = drawn.iter().max_by_key(|l| l.len()).expect("the stroke is painted while the button is down");+ let near = |a: Pos2, b: Pos2| (a - b).length() < 2.0;+ assert!(near(stroke[0], start), "it starts where the press was: {:?}", stroke[0]);+ assert!(path.iter().all(|p| stroke.iter().any(|q| near(*p, *q))), "it follows the pointer: {stroke:?}");+ assert_eq!(items(&h), before, "nothing is made before the release");+ // Letting go makes the path and ends the preview.+ h.drop_at(*path.last().unwrap());+ h.run_steps(3);+ assert_eq!(items(&h), before + 1);+ let app = &mut h.state_mut().app;+ let view = app.view_info();+ assert!(app.session.overlays(view).is_empty(), "the preview is gone");+ }}++ #[cfg(test)]+ mod scrollbar_tests {+ use egui::{Event, Modifiers, PointerButton};+ use egui_kittest::Harness;++ use super::*;+ use crate::test_window::{Window, open, wheel};++ fn window() -> Harness<'static, Window> {+ let mut h = open(DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()), vec2(1440.0, 900.0));+ // Zoomed in so both axes scroll.+ set_zoom(&mut h.state_mut().app, 2.0);+ h.run_steps(3);+ h+ }++ fn origin(h: &Harness<'static, Window>) -> Point {+ h.state().app.view().map(|v| v.origin).unwrap_or_default()+ }++ /// The scrollbar's track and thumb as the canvas lays them out for the current view, and+ /// the content pixels per thumb pixel.+ fn bar(h: &Harness<'static, Window>, vertical: bool) -> (Rect, Rect, f32) {+ let app = &h.state().app;+ let rect = app.canvas_rect.unwrap();+ let st = app.session.active().unwrap();+ let xf = Xf::new(rect, app.view().unwrap());+ let cb = xf.rect(CanvasLayout::new(&st.doc, st.editing_parents).pasteboard);+ let outer = Rect::from_min_max(rect.min, rect.max + vec2(SCROLLBAR, SCROLLBAR));+ scrollbar_rects(outer, rect, cb, vertical)+ }++ /// A primary-button drag from `a` to `b` in a few moves, with `mods` held throughout.+ fn drag(h: &mut Harness<'static, Window>, a: Pos2, b: Pos2, mods: Modifiers) {+ h.event(Event::ModifiersChanged(mods));+ h.hover_at(a);+ h.step();+ h.event(Event::PointerButton { pos: a, button: PointerButton::Primary, pressed: true, modifiers: mods });+ h.step();+ for n in 1..=4 {+ h.hover_at(a + (b - a) * n as f32 / 4.0);+ h.step();+ }+ h.event(Event::PointerButton { pos: b, button: PointerButton::Primary, pressed: false, modifiers: mods });+ h.event(Event::ModifiersChanged(Modifiers::NONE));+ h.run_steps(3);+ }++ #[test]+ fn document_views_have_scrollbars_beside_the_view() {+ let h = window();+ let rect = h.state().app.canvas_rect.unwrap();+ for vertical in [true, false] {+ let r = h.ctx.read_response(egui::Id::new(("canvas_scrollbar", 0u8, vertical))).expect("scrollbar").rect;+ let (track, thumb, k) = bar(&h, vertical);+ assert_eq!(r, track);+ assert!(k > 0.0, "the zoomed-in view scrolls");+ if vertical {+ assert_eq!((r.min.x, r.width(), r.min.y, r.max.y), (rect.max.x, SCROLLBAR, rect.min.y, rect.max.y));+ assert!(thumb.height() < track.height());+ } else {+ assert_eq!((r.min.y, r.height(), r.min.x, r.max.x), (rect.max.y, SCROLLBAR, rect.min.x, rect.max.x));+ assert!(thumb.width() < track.width());+ }+ }+ }++ #[test]+ fn dragging_a_thumb_pans_and_clicking_the_track_pages() {+ let mut h = window();+ let zoom = h.state().app.view().unwrap().zoom;+ // Vertical thumb: down 40 px moves the view down by 40 thumb pixels' worth of content.+ let (_, thumb, k) = bar(&h, true);+ let before = origin(&h);+ drag(&mut h, thumb.center(), thumb.center() + vec2(0.0, 40.0), Modifiers::NONE);+ let after = origin(&h);+ let want = 40.0 * k as f64 / zoom;+ assert!((after.y - before.y - want).abs() < want * 0.2, "{before:?} → {after:?}, want +{want}");+ assert_eq!(after.x, before.x);+ // Horizontal thumb: left 30 px.+ let (_, thumb, k) = bar(&h, false);+ drag(&mut h, thumb.center(), thumb.center() - vec2(30.0, 0.0), Modifiers::NONE);+ let next = origin(&h);+ let want = 30.0 * k as f64 / zoom;+ assert!((after.x - next.x - want).abs() < want * 0.2, "{after:?} → {next:?}, want -{want}");+ assert_eq!(next.y, after.y);+ // A click on the vertical track above the thumb pages up by one view.+ let (track, thumb, _) = bar(&h, true);+ assert!(thumb.min.y - track.min.y > 4.0);+ crate::test_window::click_at(&mut h, pos2(track.center().x, track.min.y + 2.0));+ let paged = origin(&h);+ let view = h.state().app.canvas_rect.unwrap().height() as f64 / zoom;+ assert!((next.y - paged.y - view).abs() < 0.01, "{next:?} → {paged:?}, want -{view}");+ }++ #[test]+ fn scrolling_the_view_moves_the_thumbs() {+ let mut h = window();+ let (_, v0, _) = bar(&h, true);+ let (_, h0, _) = bar(&h, false);+ let c = h.state().app.canvas_rect.unwrap().center();+ wheel(&mut h, c, vec2(-50.0, -80.0));+ let (_, v1, _) = bar(&h, true);+ let (_, h1, _) = bar(&h, false);+ assert!(v1.min.y > v0.min.y && h1.min.x > h0.min.x, "{v0:?} → {v1:?}, {h0:?} → {h1:?}");+ let r = h.ctx.read_response(egui::Id::new(("canvas_scrollbar", 0u8, true))).expect("scrollbar");+ assert_eq!(r.rect, bar(&h, true).0);+ }++ #[test]+ fn alt_drag_while_editing_text_pans_and_keeps_the_caret() {+ let mut h = window();+ let app = &mut h.state_mut().app;+ let rect = app.canvas_rect.unwrap();+ let xf = Xf::new(rect, app.view().unwrap());+ // A text frame filling the visible part of the page, with the caret in it.+ let (a, b) = (xf.to_canvas(rect.min + vec2(20.0, 20.0)), xf.to_canvas(rect.max - vec2(20.0, 20.0)));+ let r = app.run("frame.create", json!({"rect": [a.x, a.y, b.x, b.y], "content": "text", "text": "Hello brave world"})).unwrap();+ let sid = r["story"].as_u64().unwrap();+ app.run("tool.select", json!({"tool": "type"})).unwrap();+ app.run("text.select", json!({"story": sid, "anchor": 3, "focus": 3})).unwrap();+ assert!(app.session.wants_text());+ h.run_steps(2);+ let caret = h.state().app.session.doc().unwrap().selection.text;+ let before = origin(&h);+ let zoom = h.state().app.view().unwrap().zoom;+ let from = rect.center();+ drag(&mut h, from, from + vec2(60.0, 40.0), Modifiers::ALT);+ let after = origin(&h);+ assert!(after.x < before.x && after.y < before.y, "{before:?} → {after:?}");+ assert!((before.x - after.x - 60.0 / zoom).abs() < 15.0 / zoom, "{before:?} → {after:?}");+ assert_eq!(h.state().app.session.doc().unwrap().selection.text, caret);+ assert!(h.state_mut().app.session.wants_text(), "still editing text");+ // Without Alt the same drag selects text and leaves the view alone.+ drag(&mut h, from, from + vec2(60.0, 40.0), Modifiers::NONE);+ assert_eq!(origin(&h), after);+ }+ }diff --cc docs/ui-parity.mdindex 1910ec29e,32e53a996..c58d791e8--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@@ -1,6 -1,6 +1,6 @@@# UI and interaction parity- > **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-11 · **Change:** minor (live corners work) · **Target:** Adobe InDesign 2026 (21.6, Medium Dark, macOS)-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-11 · **Change:** minor (document views row: scrollbars, Alt pans while editing text) · **Target:** Adobe InDesign 2026 (21.6, Medium Dark, macOS)++> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-11 · **Change:** minor (live corners work; document views row: scrollbars, Alt pans while editing text) · **Target:** Adobe InDesign 2026 (21.6, Medium Dark, macOS)Tools, handles, snapping, nudging, modifiers, shortcuts, panels, menus, context menus and feel,against InDesign 2026. The look was measured from the running app