Skip to content

Commit

Permalink
Configurable Vertical Layout Padding
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter committed Feb 21, 2024
1 parent 31f8bda commit b98d992
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ public class TextLayoutManager: NSObject {
}
}

/// The amount of extra vertical padding used to lay out lines in before they come into view.
///
/// This solves a small problem with layout performance, if you're seeing layout lagging behind while scrolling,
/// adjusting this value higher may help fix that.
/// Defaults to `350`.
public var verticalLayoutPadding: CGFloat = 350 {
didSet {
setNeedsLayout()
}
}

// MARK: - Internal

weak var textStorage: NSTextStorage?
Expand Down Expand Up @@ -234,8 +245,8 @@ public class TextLayoutManager: NSObject {
func layoutLines() { // swiftlint:disable:this function_body_length
guard let visibleRect = delegate?.visibleRect, !isInTransaction, let textStorage else { return }
CATransaction.begin()
let minY = max(visibleRect.minY - 350, 0) // +-350px for a bit padding while laying out lines.
let maxY = max(visibleRect.maxY + 350, 0)
let minY = max(visibleRect.minY - verticalLayoutPadding, 0)
let maxY = max(visibleRect.maxY + verticalLayoutPadding, 0)
let originalHeight = lineStorage.height
var usedFragmentIDs = Set<UUID>()
var forceLayout: Bool = needsLayout
Expand Down

0 comments on commit b98d992

Please sign in to comment.