Expand replaces Widen: fill the window in both directions

From the development repository at 3f1da52.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ackandClaude Opus 4.8 committed 2026-10-11 19:43:17 +02:00
1 parent 51e66db9a1
commit cc0b8dbd31
9 files changed
+102 -72

No files matched your search

+38 -28
View File
@@ -1418,23 +1418,26 @@ class EndToEndTest(unittest.TestCase):
self.assertEqual(placed["placed"]["y"], upward["origin"][1] + 50)
self.assertEqual(placed["placed"]["x"], upward["origin"][0] + (upward["page"]["width"] - 300) // 2)
# Widen on a page that writing has grown on one side: the page
# comes out as wide as the window, measured from the page's own
# edges, not the sheet's (Andy, 2026-10-08).
# Expand on a page that writing has grown on one side: the page
# comes out as wide and as tall as the window, measured from the
# page's own edges, not the sheet's (Andy, 2026-10-08, 2026-10-11).
firefox.run("""
document.getElementById('desk').dispatchEvent(new WheelEvent('wheel',
{deltaY: 100, ctrlKey: true, clientX: 300, clientY: 300, bubbles: true, cancelable: true}));
""")
firefox.run("document.getElementById('zoom_widen').click();")
widened = self.wait_until(lambda s: s["page"]["width"] > grown["page"]["width"], "the page to widen")
firefox.run("document.getElementById('zoom_expand').click();")
self.wait_until(lambda s: s["page"]["width"] > grown["page"]["width"]
and s["page"]["height"] > grown["page"]["height"], "the page to expand")
measured = firefox.run("""
const r = window.kokkoja.renderer;
const desk = document.getElementById('desk');
const style = getComputedStyle(desk);
const room = desk.offsetWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
return {page: document.getElementById('page').getBoundingClientRect().width, room};
const page = document.getElementById('page').getBoundingClientRect();
return {width: page.width, height: page.height,
room: desk.offsetWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight),
roomHeight: desk.offsetHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom)};
""")
self.assertAlmostEqual(measured["page"], measured["room"], delta=1)
self.assertAlmostEqual(measured["width"], measured["room"], delta=1)
self.assertAlmostEqual(measured["height"], measured["roomHeight"], delta=1)
# The writer's tab is closed for the next test; the host's is cleared.
firefox.switch_to(guest_tab)
@@ -1654,8 +1657,8 @@ class EndToEndTest(unittest.TestCase):
time.sleep(0.5)
self.assertEqual(firefox.run("return window.kokkoja.renderer.cssPixelsPerUnit;"), host_scale)
# Widen makes the sheet itself wider, for everyone, until it fills
# the window at this zoom; the scale and what is in view stay.
# Expand makes the sheet fill the window, for everyone, at this
# zoom, in both directions; the scale and what is in view stay.
firefox.run("""
document.getElementById('desk').dispatchEvent(new WheelEvent('wheel',
{deltaY: 100, ctrlKey: true, clientX: 300, clientY: 300, bubbles: true, cancelable: true}));
@@ -1666,29 +1669,36 @@ class EndToEndTest(unittest.TestCase):
return [Math.round(b.left), Math.round(b.top), Math.round(b.width)];
""")
box_before = image_box()
firefox.run("document.getElementById('zoom_widen').click();")
widened = zoom()
# The sheet grew equally on both sides: nothing on it moved on the screen.
firefox.run("document.getElementById('zoom_expand').click();")
expanded = zoom()
# The sheet grew equally on every side: nothing on it moved on screen.
self.assertEqual(image_box(), box_before)
self.assertLess(firefox.run("return window.kokkoja.session.page.baseLeft;"), 0)
desk_width = firefox.run("""
self.assertLess(firefox.run("return window.kokkoja.session.page.baseTop;"), 0)
room = firefox.run("""
const desk = document.getElementById('desk');
const style = getComputedStyle(desk);
return desk.offsetWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
return {width: desk.offsetWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight),
height: desk.offsetHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom)};
""")
self.assertAlmostEqual(widened["width"], desk_width, delta=1)
self.assertEqual(widened["zoom"], smaller["zoom"])
page_box = firefox.run("""
const b = document.getElementById('page').getBoundingClientRect();
return {width: b.width, height: b.height};
""")
self.assertAlmostEqual(page_box["width"], room["width"], delta=1)
self.assertAlmostEqual(page_box["height"], room["height"], delta=1)
self.assertEqual(expanded["zoom"], smaller["zoom"])
wide_page = self.state()["page"]
self.assertGreater(wide_page["width"], teacher["page"]["width"])
self.assertEqual(wide_page["height"], teacher["page"]["height"])
self.assertGreater(wide_page["height"], teacher["page"]["height"])
firefox.switch_to(student_tab)
self.wait_until(lambda s: s["page"] == wide_page, "the wider page to reach the student")
self.assertTrue(firefox.run("return document.getElementById('zoom_widen').hidden;"))
self.wait_until(lambda s: s["page"] == wide_page, "the expanded page to reach the student")
self.assertTrue(firefox.run("return document.getElementById('zoom_expand').hidden;"))
self.assertEqual(firefox.run("return window.kokkoja.session.page.baseLeft;"),
-((wide_page["width"] - teacher["page"]["width"]) // 2))
# The page file carries the sheet's left edge and reads back with it.
widened_file = self.current_page("Student notebook", {}, number=3)
self.assertRegex(widened_file, r'data-base="\d+ 2100 -\d+ 0"')
# The page file carries the sheet's edges and reads back with them.
expanded_file = self.current_page("Student notebook", {}, number=3)
self.assertRegex(expanded_file, r'data-base="\d+ \d+ -\d+ -\d+"')
firefox.switch_to(teacher_tab)
# Shrink makes the sheet just large enough for what is on it, with
@@ -1725,15 +1735,15 @@ class EndToEndTest(unittest.TestCase):
firefox.run("document.getElementById('zoom_sheet').click();")
sheet_scale = firefox.run("return window.kokkoja.renderer.cssPixelsPerUnit;")
self.assertLess(sheet_scale, fitted_scale)
self.assertAlmostEqual(sheet_scale, min(desk_width / 2970, firefox.run("""
self.assertAlmostEqual(sheet_scale, min(room["width"] / 2970, firefox.run("""
const desk = document.getElementById('desk');
const style = getComputedStyle(desk);
return desk.offsetHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
""") / 2100), places=4)
# Widened again, from the shrunk sheet, for the room the rest needs.
# Expanded again, from the shrunk sheet, for the room the rest needs.
firefox.run("document.getElementById('zoom_fit').click();")
firefox.run("document.getElementById('zoom_widen').click();")
self.wait_until(lambda s: s["page"]["width"] > shrunk_page["page"]["width"], "the page widened again")
firefox.run("document.getElementById('zoom_expand').click();")
self.wait_until(lambda s: s["page"]["width"] > shrunk_page["page"]["width"], "the page expanded again")
firefox.run("document.getElementById('zoom_fit').click();")
teacher = self.state()