Skip to content

Commit c7016f6

Browse files
Added scroll past end behavior
1 parent 33c0971 commit c7016f6

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Sources/CodeEditTextView/TextSelectionManager/TextSelectionManager.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ public class TextSelectionManager: NSObject {
221221
.getLine(atOffset: range.location - (selectedLine.range.location))?
222222
.height
223223
?? layoutManager?.estimateLineHeight()
224-
225224
}
226225

227226
/// Removes all cursor views and stops the cursor blink timer.

Sources/CodeEditTextView/TextView/TextView+Insert.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import AppKit
9+
import TextStory
910

1011
extension TextView {
1112
override public func insertNewline(_ sender: Any?) {

Sources/CodeEditTextView/TextView/TextView+Layout.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ extension TextView {
6464
public func updateFrameIfNeeded() -> Bool {
6565
var availableSize = scrollView?.contentSize ?? .zero
6666
availableSize.height -= (scrollView?.contentInsets.top ?? 0) + (scrollView?.contentInsets.bottom ?? 0)
67-
let newHeight = max(layoutManager.estimatedHeight(), availableSize.height)
67+
68+
let extraHeight = scrollPastEnd ? availableSize.height * scrollPastEndAmount : 0
69+
let newHeight = max(layoutManager.estimatedHeight() + extraHeight, availableSize.height)
6870
let newWidth = layoutManager.estimatedWidth()
6971

7072
var didUpdate = false

Sources/CodeEditTextView/TextView/TextView.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ public class TextView: NSView, NSTextContent {
107107
}
108108
}
109109

110+
/// Determines if the text view should allow scrolling past the end of the document
111+
public var scrollPastEnd: Bool = true {
112+
didSet {
113+
updateFrameIfNeeded()
114+
}
115+
}
116+
117+
/// The amount of extra space to add when scrolling past end is enabled, as a percentage of the viewport height
118+
public var scrollPastEndAmount: CGFloat = 0.5 {
119+
didSet {
120+
if scrollPastEnd {
121+
updateFrameIfNeeded()
122+
}
123+
}
124+
}
125+
110126
/// Whether or not the editor should wrap lines
111127
public var wrapLines: Bool {
112128
get {

0 commit comments

Comments
 (0)