Skip to content

Commit bac7e3a

Browse files
committed
Fix gutter view positioning and clipping
The gutter view now properly clips its contents and maintains correct positioning when scrolling. This fixes positioning issues by using the frame's minX instead of bounds.minX for line number cell placement and adds explicit setting of both x and y coordinates when positioning the gutter view during layout.
1 parent a7d2e88 commit bac7e3a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/STTextViewUIKit/Gutter/STGutterView.swift

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ open class STGutterView: UIView {
9292
markerContainerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
9393

9494
super.init(frame: frame)
95+
clipsToBounds = true
9596
isUserInteractionEnabled = true
9697
isOpaque = false
9798

Sources/STTextViewUIKit/STTextView+Gutter.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ extension STTextView {
3535

3636
internal func layoutGutter() {
3737
if let gutterView {
38-
gutterView.frame.origin = contentOffset
38+
// gutter view floats on the edge
39+
// the contentOffset is the adjustment to make it visible
40+
gutterView.frame.origin.x = contentOffset.x
41+
gutterView.frame.origin.y = contentOffset.y
3942
gutterView.frame.size.height = visibleSize.height
4043
layoutGutterLineNumbers()
4144
}
@@ -90,7 +93,7 @@ extension STTextView {
9093

9194
numberCell.frame = CGRect(
9295
origin: CGPoint(
93-
x: bounds.minX,
96+
x: frame.minX,
9497
y: selectionFrame.origin.y - contentOffset.y
9598
),
9699
size: CGSize(
@@ -225,7 +228,7 @@ extension STTextView {
225228

226229
numberCell.frame = CGRect(
227230
origin: CGPoint(
228-
x: bounds.minX,
231+
x: frame.minX,
229232
y: lineFragmentFrame.origin.y
230233
),
231234
size: CGSize(

0 commit comments

Comments
 (0)