Skip to content

Commit 02202a8

Browse files
Added scroll past end behavior (overscroll) (#77)
### Description Added optional functionality to allow the user to scroll past the end of the document, like in Xcode or VSCode. ### Related Issues Closes #76 ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots This is showing an extra 50% of the available screen. It will properly update when resizing the window as well. https://github.com/user-attachments/assets/40ef3f49-1a8b-4cad-a975-9cb9429ce32b
1 parent fe36e69 commit 02202a8

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Sources/CodeEditTextView/TextSelectionManager/TextSelectionManager.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ public class TextSelectionManager: NSObject {
219219
.getLine(atOffset: range.location - (selectedLine.range.location))?
220220
.height
221221
?? layoutManager?.estimateLineHeight()
222-
223222
}
224223

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

Sources/CodeEditTextView/TextView/TextView+Layout.swift

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

7173
var didUpdate = false

Sources/CodeEditTextView/TextView/TextView.swift

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

110+
/// The amount of extra space to add when overscroll is enabled, as a percentage of the viewport height
111+
public var overscrollAmount: CGFloat = 0.5 {
112+
didSet {
113+
if overscrollAmount < 0 {
114+
overscrollAmount = 0
115+
}
116+
updateFrameIfNeeded()
117+
}
118+
}
119+
110120
/// Whether or not the editor should wrap lines
111121
public var wrapLines: Bool {
112122
get {

0 commit comments

Comments
 (0)