Skip to content

Commit 05f548a

Browse files
committed
Scroll to visible on content view
The `scrollRangeToVisible` method now scrolls the content view to the visible range, adjusting the target rect to account for the gutter view width. This ensures the proper content area is made visible. Also fix a small typo in the README.
1 parent b873f53 commit 05f548a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ The `STTextView` is an `NSView` subclass and can be initialized like any other v
116116
import STTextView
117117

118118
let textView = STTextView()
119-
view.addSubView(textView)
119+
view.addSubview(textView)
120120
```
121121

122122
(macOS) add to scroll view

Sources/STTextViewAppKit/STTextView.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,11 @@ import AVFoundation
12671267
rect = rect.inset(by: .init(top: 0, left: -textContainer.lineFragmentPadding, bottom: 0, right: -textContainer.lineFragmentPadding))
12681268
}
12691269

1270-
return scrollToVisible(rect)
1270+
// scroll to visible IN clip view (ignoring gutter view overlay)
1271+
// adjust rect to mimick it's size to include gutter overlay
1272+
rect.origin.x -= gutterView?.frame.width ?? 0
1273+
rect.size.width += gutterView?.frame.width ?? 0
1274+
return contentView.scrollToVisible(rect)
12711275
}
12721276

12731277
open func scrollRangeToVisible(_ range: NSRange) {

0 commit comments

Comments
 (0)