ElyDoc: a page stays centred and zoom stays on the page; only a sheet grows past its size (R2.7)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 02:38:46 -04:00
1 parent 9fe28f072b
commit 1b1148a410
3 files changed
+34 -3

No files matched your search

+5 -3
View File
@@ -49,9 +49,11 @@ impl LokView {
self.geom.twips_of(self.viewport.0) - fx,
self.geom.twips_of(self.viewport.1) - fy,
);
// Room past the target, in print twips for later zooms.
let need = self.print_of((x + w + vw + fx, y + h + vh + fy));
self.reach = (self.reach.0.max(need.0), self.reach.1.max(need.1));
// Only a sheet grows where it jumps; pages keep their size.
if self.sheet.is_some() {
let need = self.print_of((x + w + vw + fx, y + h + vh + fy));
self.reach = (self.reach.0.max(need.0), self.reach.1.max(need.1));
}
if x >= fx && (x < fx + self.scroll.0 || x + w > fx + self.scroll.0 + vw) {
self.scroll.0 = x - fx - vw / 2;
}
+2
View File
@@ -359,6 +359,8 @@ fn a_moved_cursor_scrolls_into_view_and_a_still_one_does_not() {
view.scroll_by(0.0, 1_000_000.0, cx);
view.apply_batch(batch(), None, cx);
assert_eq!(view.scroll.1, 0, "a still cursor leaves the scroll alone");
// Only a sheet grows past the kernel's size.
view.sheet = Some(crate::sheet::Geometry::default());
let far = view.doc_size.1 + 20_000;
let cell = crate::Cell {
cursor: Some((1418, far, 1280, 277)),
+27
View File
@@ -88,3 +88,30 @@ fn a_resized_slide_reaches_the_view_and_still_fits() {
})
});
}
#[test]
fn a_page_stays_centred_when_the_cursor_moves() {
let Some(install) = crate::client::tests::install() else {
eprintln!("SKIP: no pinned LOK build");
return;
};
let cx = gpui::TestAppContext::single();
cx.update(|app| {
let (view, _) = live_view(app, &install);
view.update(app, |view, cx| {
let wide = Bounds { origin: point(px(0.0), px(0.0)), size: size(px(2400.0), px(900.0)) };
view.prepare(wide);
let centred = view.spare.0;
assert!(centred > 0.0, "a page narrower than the view sits centred");
view.show((1440, 1440, 20, 300), cx);
view.prepare(wide);
assert_eq!(view.spare.0, centred, "moving the cursor keeps it centred");
let narrow = Bounds { origin: point(px(0.0), px(0.0)), size: size(px(800.0), px(900.0)) };
view.prepare(narrow);
view.set_zoom(2.0, cx);
view.prepare(narrow);
let right = view.scroll.0 + view.geom.twips_of(view.viewport.0);
assert!(right <= view.doc_size.0, "no grey past the page: {right} > {}", view.doc_size.0);
})
});
}