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