Skip to content

Commit

Permalink
Reset container size
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Oct 9, 2023
1 parent 7771b9a commit 5ce821f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/STTextView/STTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ open class STTextView: NSView, NSTextInput, NSTextContent {
}

// Update text view frame size
// Receiver changes its height to fit the height of its text (akin to isVerticallyResizable = true)
internal func updateFrameSizeIfNeeded() {
let currentSize = frame.size
let viewportBounds = textLayoutManager.textViewportLayoutController.viewportBounds
Expand All @@ -988,20 +989,27 @@ open class STTextView: NSView, NSTextInput, NSTextContent {

let proposedSize = CGSize(width: proposedWidth, height: proposedHeight)
if !currentSize.isAlmostEqual(to: proposedSize) {
setFrameSize(proposedSize)
// call setFrameSize and updateTextContainerSizeIfNeeded()
// that is unfortunate sinze frame is set based on container size itself
frame.size = proposedSize
}
}

// Update textContainer width to match textview width if track textview width
// widthTracksTextView = true
fileprivate func updateTextContainerSizeIfNeeded() {
var proposedSize = textContainer.size

if textContainer.widthTracksTextView, !textContainer.size.width.isAlmostEqual(to: visibleRect.width) {
proposedSize.width = visibleRect.width
} else if !textContainer.widthTracksTextView {
proposedSize.width = CGFloat.infinity
}

if textContainer.heightTracksTextView, !textContainer.size.height.isAlmostEqual(to: bounds.height) {
proposedSize.height = bounds.height
} else if !textContainer.heightTracksTextView {
proposedSize.height = CGFloat.infinity
}

if !textContainer.size.isAlmostEqual(to: proposedSize) {
Expand Down

0 comments on commit 5ce821f

Please sign in to comment.