From b4bff7ffe1c414e9dd450542c5f7dee94e1e033c Mon Sep 17 00:00:00 2001 From: David Richardson Date: Fri, 23 Oct 2026 19:32:07 -0600 Subject: [PATCH] AppKit: Fit a tracking text container inside the text view's inset A text container that tracked its text view's size took the text view's full width, while the text started after the text container inset, so lines could run past the visible right edge. It now follows Cocoa: a tracking container fills the text view minus the inset on both sides. * CPTextView/CPTextContainer.j: Subtract the text container inset on both sides when tracking the text view's width and height. * CPTextView/CPTextView.j: Refit the text container when a text view is created and when its text container inset changes. --- AppKit/CPTextView/CPTextContainer.j | 9 ++++++--- AppKit/CPTextView/CPTextView.j | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/AppKit/CPTextView/CPTextContainer.j b/AppKit/CPTextView/CPTextContainer.j index d343b397a..9d9d54b3c 100644 --- a/AppKit/CPTextView/CPTextContainer.j +++ b/AppKit/CPTextView/CPTextContainer.j @@ -193,13 +193,16 @@ CPLineMovesUp = 4; - (void)textViewFrameChanged:(CPNotification)aNotification { - var newSize = CGSizeMake(_size.width, _size.height); + // As in Cocoa, a tracking container fills the text view inside its text container inset on both sides. + var newSize = CGSizeMake(_size.width, _size.height), + frameSize = [_textView frame].size, + inset = [_textView textContainerInset]; if (_widthTracksTextView) - newSize.width = [_textView frame].size.width; + newSize.width = MAX(0.0, frameSize.width - 2.0 * inset.width); if (_heightTracksTextView) - newSize.height = [_textView frame].size.height; + newSize.height = MAX(0.0, frameSize.height - 2.0 * inset.height); [self setContainerSize:newSize]; } diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index a39c89288..246c89120 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -210,6 +210,9 @@ var kDelegateRespondsTo_textShouldBeginEditing [self _init]; [aContainer setTextView:self]; + // Fit a container that tracks the text view's size inside the text container inset. + [aContainer textViewFrameChanged:nil]; + [self setEditable:YES]; [self setSelectable:YES]; [self setRichText:NO]; @@ -812,6 +815,9 @@ var kDelegateRespondsTo_textShouldBeginEditing { _textContainerInset = aSize; [self invalidateTextContainerOrigin]; + + // A container that tracks the text view's size must shrink or grow with the new inset. + [_textContainer textViewFrameChanged:nil]; } - (void)invalidateTextContainerOrigin