@@ -43,7 +43,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
4343 public var font : NSFont
4444
4545 /// The overScrollLineCount to use for the textView over scroll
46- public var overScrollLineCount : Int
46+ public var overScrollRatio : Double
4747
4848 // MARK: - Highlighting
4949
@@ -59,15 +59,15 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
5959 theme: EditorTheme ,
6060 tabWidth: Int ,
6161 cursorPosition: Published < ( Int , Int ) > . Publisher ? = nil ,
62- overScrollLineCount : Int
62+ overScrollRatio : Double
6363 ) {
6464 self . text = text
6565 self . language = language
6666 self . font = font
6767 self . theme = theme
6868 self . tabWidth = tabWidth
6969 self . cursorPosition = cursorPosition
70- self . overScrollLineCount = overScrollLineCount
70+ self . overScrollRatio = overScrollRatio
7171 super. init ( nibName: nil , bundle: nil )
7272 }
7373
@@ -117,8 +117,6 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
117117
118118 scrollView. translatesAutoresizingMaskIntoConstraints = false
119119
120- scrollView. contentInsets. bottom = Double ( overScrollLineCount) * lineHeight
121-
122120 self . view = scrollView
123121
124122 NSLayoutConstraint . activate ( [
@@ -143,6 +141,11 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
143141 self . cursorPositionCancellable = self . cursorPosition? . sink ( receiveValue: { value in
144142 self . setCursorPosition ( value)
145143 } )
144+
145+ NotificationCenter . default. addObserver ( forName: NSWindow . didResizeNotification, object: nil , queue: . main) { [ weak self] _ in
146+ guard let self = self else { return }
147+ ( self . view as? NSScrollView ) ? . contentView. contentInsets. bottom = self . bottomContentInsets
148+ }
146149 }
147150
148151 internal func setUpHighlighting( ) {
@@ -176,6 +179,18 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
176179 return paragraph
177180 }
178181
182+ /// ScrollView's bottom inset using as editor overscroll
183+ private var bottomContentInsets : CGFloat {
184+ let height = view. frame. height
185+ var inset = overScrollRatio * height
186+
187+ if height - inset < lineHeight {
188+ inset = height - lineHeight
189+ }
190+
191+ return max ( inset, . zero)
192+ }
193+
179194 /// Reloads the UI to apply changes to ``STTextViewController/font``, ``STTextViewController/theme``, ...
180195 internal func reloadUI( ) {
181196 textView? . font = font
@@ -189,7 +204,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
189204 rulerView? . separatorColor = theme. invisibles
190205 rulerView? . baselineOffset = baselineOffset
191206
192- ( view as? NSScrollView ) ? . contentInsets. bottom = Double ( overScrollLineCount ) * lineHeight
207+ ( view as? NSScrollView ) ? . contentView . contentInsets. bottom = bottomContentInsets
193208
194209 setStandardAttributes ( )
195210 }
0 commit comments