Shrink ignores what cannot be seen; blank lines at a block's end go

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
ackandClaude Fable 5.1 committed 2026-10-14 01:48:56 +02:00
1 parent bb41047e85
commit 56ab259cd4
5 files changed
+158 -11

No files matched your search

+79
View File
@@ -14,6 +14,7 @@ the second participant sees it at the end.
import base64
import json
import math
import os
import pathlib
import re
@@ -1587,6 +1588,84 @@ class EndToEndTest(unittest.TestCase):
firefox.run("document.getElementById('manual_close').click();")
self.assertFalse(firefox.run("return document.getElementById('manual_dialog').open;"))
def test_shrink_ignores_the_invisible(self):
"""Andy, 2026-10-14: what cannot be seen does not count for Shrink:
strokes and free text in the paper's white, and the blank lines at
the end of a text block, which go when its typing ends (a box
grown by them shrinks back) and, for one's own, at Shrink."""
firefox = self.firefox
firefox.go(self.address("Late"))
self.enter_name("Shrinker", "start_session")
state = self.wait_until(lambda s: s["page"]["number"] == 1, "the page")
scale = firefox.run("return window.kokkoja.renderer.cssPixelsPerUnit;")
origin = state["origin"]
px = lambda x: (x - origin[0]) * scale
py = lambda y: (y - origin[1]) * scale
swatch = lambda i: firefox.run(f"document.querySelectorAll('#colors .swatch')[{i}].click();")
# A black stroke, then a white stroke and white free text far to the
# right and below, where they would widen the shrunk page if counted.
firefox.drag("#page", px(500), py(500), px(900), py(520))
self.wait_until(lambda s: len(s["layers"]["Shrinker"]) == 1 and s["layers"]["Shrinker"][0]["done"], "the black stroke")
swatch(4)
firefox.drag("#page", px(2000), py(1500), px(2500), py(1600))
self.wait_until(lambda s: len(s["layers"]["Shrinker"]) == 2 and s["layers"]["Shrinker"][1]["done"], "the white stroke")
self.assertEqual(self.state()["layers"]["Shrinker"][1]["id"] and firefox.run(
"return [...window.kokkoja.session.ownLayer.strokes.values()][1].color;"), "#ffffff")
firefox.run("document.querySelector('[data-tool=text]').click();")
firefox.run(TEXT_GESTURE, px(2000) / state["page"]["width"] / scale, py(600) / state["page"]["height"] / scale,
px(2000) / state["page"]["width"] / scale, py(600) / state["page"]["height"] / scale)
firefox.type_into(".text_field", "unsichtbar")
# A small text rectangle, in black, grown by blank lines typed after
# the word: finishing removes them and the box shrinks back to its
# one line. Dragging it open finishes the white text first; the
# colour is chosen after, since a change restyles the block typed in.
fx = lambda x: px(x) / (state["page"]["width"] * scale)
fy = lambda y: py(y) / (state["page"]["height"] * scale)
firefox.run(TEXT_GESTURE, fx(500), fy(800), fx(1100), fy(830))
swatch(0)
firefox.type_into(".text_field", "Antwort\n\n\n\n")
grown = self.wait_until(lambda s: len(s["texts"]["Shrinker"]) == 2 and s["texts"]["Shrinker"][1]["text"] == "Antwort\n\n\n\n",
"the box typed in")
box = grown["texts"]["Shrinker"][1]
self.assertGreater(box["height"], 300, "grown by the blank lines: five lines of about 70 units")
self.assertEqual(box["height"], math.ceil(box["boxHeight"]))
firefox.run("document.querySelector('[data-tool=pen]').click();")
trimmed = self.wait_until(lambda s: s["texts"]["Shrinker"][1]["text"] == "Antwort", "the blank lines gone")
box = trimmed["texts"]["Shrinker"][1]
self.assertEqual(box["height"], math.ceil(box["boxHeight"]))
self.assertLess(box["height"], 80, "back to one line")
self.assertEqual(trimmed["texts"]["Shrinker"][0]["text"], "unsichtbar")
self.assertEqual(firefox.run("return [...window.kokkoja.session.ownLayer.texts.values()][0].color;"), "#ffffff")
# Shrink: the sheet holds the black stroke and the box with the
# margin, and nothing of the white marks.
before = self.state()["page"]
firefox.run("document.getElementById('zoom_shrink').click();")
shrunk = self.wait_until(lambda s: s["page"]["width"] < before["width"], "the shrunk page")
sheet = firefox.run("const p = window.kokkoja.session.page; return [p.baseLeft, p.baseTop, p.baseWidth, p.baseHeight];")
self.assertAlmostEqual(sheet[0], 500 - 14 - 50, delta=4) # the stroke's reach, then the margin
self.assertAlmostEqual(sheet[1], 500 - 14 - 50, delta=4)
self.assertAlmostEqual(sheet[0] + sheet[2], 1100 + 50, delta=4) # the box's right edge
self.assertAlmostEqual(sheet[1] + sheet[3], 800 + box["height"] + 50, delta=4)
# A box of one's own that still has blank lines at its end, as one
# from a page made before the trimming would, is trimmed by Shrink
# itself, as one gesture to undo. Finishing typing trims now, so
# such a block is made by script here, the way a loaded page is.
firefox.run("""
const s = window.kokkoja.session;
const b = [...s.ownLayer.texts.values()][1];
b.text += '\\n\\n\\n';
b.lines = [...b.lines, '', '', ''];
s.setText(b);
""")
self.wait_until(lambda s: s["texts"]["Shrinker"][1]["text"] == "Antwort\n\n\n", "the blank lines on the block")
firefox.run("document.getElementById('zoom_shrink').click();")
self.wait_until(lambda s: s["texts"]["Shrinker"][1]["text"] == "Antwort", "trimmed by Shrink")
firefox.run("document.getElementById('undo').click();")
self.wait_until(lambda s: s["texts"]["Shrinker"][1]["text"] == "Antwort\n\n\n", "the trim undone")
def test_text_being_typed_stays_on_the_page_left(self):
"""Andy, 2026-10-06: a guest was typing when the host pressed New,
and the text reappeared on the new page."""