Skip to content

Commit 95878e9

Browse files
yusufozgullukepistrol
authored andcommitted
Add editor over scroll
1 parent bfe2746 commit 95878e9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Sources/CodeEditTextView/CodeEditTextView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
2727
font: Binding<NSFont>,
2828
tabWidth: Binding<Int>,
2929
lineHeight: Binding<Double>,
30+
overScrollLineCount: Binding<Int> = .constant(0),
3031
cursorPosition: Published<(Int, Int)>.Publisher? = nil
3132
) {
3233
self._text = text
@@ -35,6 +36,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
3536
self._font = font
3637
self._tabWidth = tabWidth
3738
self._lineHeight = lineHeight
39+
self._overScrollLineCount = overScrollLineCount
3840
self.cursorPosition = cursorPosition
3941
}
4042

@@ -44,6 +46,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
4446
@Binding private var font: NSFont
4547
@Binding private var tabWidth: Int
4648
@Binding private var lineHeight: Double
49+
@Binding private var overScrollLineCount: Int
4750
private var cursorPosition: Published<(Int, Int)>.Publisher?
4851

4952
public typealias NSViewControllerType = STTextViewController
@@ -55,7 +58,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
5558
font: font,
5659
theme: theme,
5760
tabWidth: tabWidth,
58-
cursorPosition: cursorPosition
61+
cursorPosition: cursorPosition,
62+
overScrollLineCount: overScrollLineCount
5963
)
6064
controller.lineHeightMultiple = lineHeight
6165
return controller
@@ -67,6 +71,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
6771
controller.theme = theme
6872
controller.tabWidth = tabWidth
6973
controller.lineHeightMultiple = lineHeight
74+
controller.overScrollLineCount = overScrollLineCount
7075
controller.reloadUI()
7176
return
7277
}

Sources/CodeEditTextView/STTextViewController.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
4242
/// The font to use in the `textView`
4343
public var font: NSFont
4444

45+
/// The overScrollLineCount to use for the textView over scroll
46+
public var overScrollLineCount: Int
47+
4548
// MARK: - Highlighting
4649

4750
internal var highlighter: Highlighter?
@@ -55,14 +58,16 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
5558
font: NSFont,
5659
theme: EditorTheme,
5760
tabWidth: Int,
58-
cursorPosition: Published<(Int, Int)>.Publisher? = nil
61+
cursorPosition: Published<(Int, Int)>.Publisher? = nil,
62+
overScrollLineCount: Int
5963
) {
6064
self.text = text
6165
self.language = language
6266
self.font = font
6367
self.theme = theme
6468
self.tabWidth = tabWidth
6569
self.cursorPosition = cursorPosition
70+
self.overScrollLineCount = overScrollLineCount
6671
super.init(nibName: nil, bundle: nil)
6772
}
6873

@@ -112,6 +117,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
112117

113118
scrollView.translatesAutoresizingMaskIntoConstraints = false
114119

120+
scrollView.contentInsets.bottom = Double(overScrollLineCount) * lineHeight
121+
115122
self.view = scrollView
116123

117124
NSLayoutConstraint.activate([
@@ -182,6 +189,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
182189
rulerView?.separatorColor = theme.invisibles
183190
rulerView?.baselineOffset = baselineOffset
184191

192+
(view as? NSScrollView)?.contentInsets.bottom = Double(overScrollLineCount) * lineHeight
193+
185194
setStandardAttributes()
186195
}
187196

0 commit comments

Comments
 (0)