From 9b5a0fbbfbebcb9d08f2f2f84f82893508e2d42f Mon Sep 17 00:00:00 2001 From: David Richardson Date: Sat, 24 Oct 2026 15:55:54 -0600 Subject: [PATCH] AppKit: Maintain proper line height for overflowing attachments in CPTypesetter When text attachments (such as tables or wide images) exceeded container width, `CPTypesetter` correctly forced a line break following the attachment but erroneously reverted the line's height and baseline to pre-attachment metrics. Consequently, oversized attachments rendered on the baseline of preceding text, causing them to overlap and obscure content above them in narrowed viewports. * AppKit/CPTextView/CPTypesetter.j: - Update line layout logic to incorporate attachment dimensions into line height and baseline calculations when line breaks encompass overflowing attachments. * Tests/Manual/TextEditor/WORKLIST.md: - Mark wide/overflowing table layout tests as completed. Attachments and tables wider than the text container now correctly occupy their own distinct lines without overlapping preceding content. --- AppKit/CPTextView/CPTypesetter.j | 10 ++++++++++ Tests/Manual/TextEditor/WORKLIST.md | 1 + 2 files changed, 11 insertions(+) diff --git a/AppKit/CPTextView/CPTypesetter.j b/AppKit/CPTextView/CPTypesetter.j index b9e6ac6d6..3e498cbc4 100644 --- a/AppKit/CPTextView/CPTypesetter.j +++ b/AppKit/CPTextView/CPTypesetter.j @@ -510,6 +510,16 @@ var _CPTypesetterDecimalSeparator = function() if (viewSize.height > _lineHeight) _lineHeight = viewSize.height - descent + leading; + // An attachment wider than the container stays on the line it overflows, so a break + // there keeps the line's height and baseline with the attachment's size applied. + // Otherwise the attachment would be placed on the baseline of the text before it, + // and drawn above its line. + if (CPMaxRange(wrapRange) === CPMaxRange(lineRange)) + { + wrapRange._height = _lineHeight; + wrapRange._base = _lineBase; + } + ascent = viewSize.height; break; } diff --git a/Tests/Manual/TextEditor/WORKLIST.md b/Tests/Manual/TextEditor/WORKLIST.md index d9e2ac21d..3c82b4630 100644 --- a/Tests/Manual/TextEditor/WORKLIST.md +++ b/Tests/Manual/TextEditor/WORKLIST.md @@ -91,4 +91,5 @@ How the text system works, for the entries below: `CPTextView` does not use CSS - Copy and paste within TextEditor with Command-C and Command-V, in one document and between documents: images, tables, including text edited in their cells, and lists are kept. - Table cells can be edited, as a first pass. - Pasting text with several images and a table: the table appears in place at once, and tables, images and text below a change move with their lines. +- A table wider than the text stays on its own line below the text before it when the window is narrowed, and is clipped at the right edge, without a horizontal scroll bar, as in Cocoa when text wraps to the window. - Builds with both the legacy toolchain and capp-build.