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

+20
View File
@@ -146,3 +146,23 @@ export function layoutText(text, width, size, family) {
boxHeight: Math.ceil(size * TOP_GAP + lines.length * size * LINE_HEIGHT),
};
}
/**
* Remove the blank lines at the end of a block's text (Andy, 2026-10-14:
* they cannot be seen, and Shrink should keep no room for them) and lay
* the block out again. A text rectangle that is exactly as tall as its
* lines, which is what a box grown by typing is, shrinks back to the
* lines that remain; one dragged taller than its lines keeps its height,
* since that room was asked for.
* @param {import('./page_model.js').TextBlock} block
* @returns {boolean} Whether anything changed.
*/
export function trimTrailingBlankLines(block) {
const trimmed = block.text.replace(/(?:\n[ \t]*)+$/, '');
if (trimmed === block.text) return false;
const grown = block.height !== null && block.height === Math.ceil(block.boxHeight);
block.text = trimmed;
Object.assign(block, layoutText(block.text, block.width, block.size, block.font));
if (grown) block.height = Math.ceil(block.boxHeight);
return true;
}