AppKit: Correct vertical sizing calculation for resizable CPTextView instances

Vertically resizable CPTextView instances previously calculated frame heights
using metrics from the first character, second-to-last character, and extra
line fragment, omitting the bounding box of the final character. Consequently,
trailing elements such as bottom-anchored image attachments were clipped,
and vertical scroll bars failed to match content bounds following scaling
or layout updates.

* AppKit/CPTextView/CPTextView.j:
  - Include the final character's bounding rectangle when computing view height to fit text.

* Tests/Manual/TextEditor/WORKLIST.md:
  - Mark wide image fitting tests as completed.

CPTextView containers now fully display trailing content and maintain accurate vertical scroll bar scaling.
This commit is contained in:
David Richardson committed 2026-10-24 12:50:16 -06:00
1 parent df78974183
commit e8eaed2e1f
2 files changed
+6 -1

No files matched your search

+4
View File
@@ -2658,6 +2658,10 @@ Sets the selection to a range of characters in response to user action.
maxSize = [self maxSize],
rect = CGRectUnion([_layoutManager boundingRectForGlyphRange:CPMakeRange(0, 1) inTextContainer:_textContainer],
[_layoutManager boundingRectForGlyphRange:CPMakeRange(MAX(0, [_layoutManager numberOfCharacters] - 2), 1) inTextContainer:_textContainer]);
// The last character can be taller than its line's text, as an image attachment at the end
// of the text is, so the view also fits it.
rect = CGRectUnion(rect, [_layoutManager boundingRectForGlyphRange:CPMakeRange(MAX(0, [_layoutManager numberOfCharacters] - 1), 1) inTextContainer:_textContainer]);
if ([_layoutManager extraLineFragmentTextContainer] === _textContainer)
rect = CGRectUnion(rect, [_layoutManager extraLineFragmentRect]);