Skip to content

Commit 8d3cd9b

Browse files
Change overscroll behavior to be handled inside TextView
1 parent f28e759 commit 8d3cd9b

File tree

4 files changed

+9
-46
lines changed

4 files changed

+9
-46
lines changed

Sources/CodeEditSourceEditor/Controller/TextViewController+IndentLines.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//
22
// TextViewController+IndentLines.swift
3-
//
3+
// CodeEditTextView
44
//
55
// Created by Ludwig, Tom on 11.09.24.
66
//
77

8-
import CodeEditTextView
98
import AppKit
9+
import CodeEditTextView
1010

1111
extension TextViewController {
1212
/// Handles indentation and unindentation
@@ -23,7 +23,7 @@ extension TextViewController {
2323
guard !cursorPositions.isEmpty else { return }
2424

2525
textView.undoManager?.beginUndoGrouping()
26-
for cursorPosition in self.cursorPositions.reversed() {
26+
for cursorPosition in self.cursorPositions.reversed() {
2727
// get lineindex, i.e line-numbers+1
2828
guard let lineIndexes = getHighlightedLines(for: cursorPosition.range) else { continue }
2929

Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ extension TextViewController {
6767
} else {
6868
scrollView.automaticallyAdjustsContentInsets = true
6969
}
70-
scrollView.contentInsets.bottom = (contentInsets?.bottom ?? 0) + bottomContentInsets
70+
scrollView.contentInsets.bottom = contentInsets?.bottom ?? 0
7171
}
7272
}

Sources/CodeEditSourceEditor/Controller/TextViewController.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ public class TextViewController: NSViewController {
104104
///
105105
/// Measured in a percentage of the view's total height, meaning a `0.3` value will result in overscroll
106106
/// of 1/3 of the view.
107-
public var editorOverscroll: CGFloat
107+
public var editorOverscroll: CGFloat {
108+
didSet {
109+
textView.overscrollAmount = editorOverscroll
110+
}
111+
}
108112

109113
/// Whether the code editor should use the theme background color or be transparent
110114
public var useThemeBackground: Bool
@@ -183,18 +187,6 @@ public class TextViewController: NSViewController {
183187

184188
internal var cancellables = Set<AnyCancellable>()
185189

186-
/// ScrollView's bottom inset using as editor overscroll
187-
package var bottomContentInsets: CGFloat {
188-
let height = view.frame.height
189-
var inset = editorOverscroll * height
190-
191-
if height - inset < font.lineHeight * lineHeightMultiple {
192-
inset = height - font.lineHeight * lineHeightMultiple
193-
}
194-
195-
return max(inset, .zero)
196-
}
197-
198190
/// The trailing inset for the editor. Grows when line wrapping is disabled.
199191
package var textViewTrailingInset: CGFloat {
200192
// See https://github.com/CodeEditApp/CodeEditTextView/issues/66

Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,6 @@ final class TextViewControllerTests: XCTestCase {
6363
XCTAssertEqual(color4, NSColor.textColor)
6464
}
6565

66-
// MARK: Overscroll
67-
68-
func test_editorOverScroll() throws {
69-
let scrollView = try XCTUnwrap(controller.view as? NSScrollView)
70-
scrollView.frame = .init(x: .zero,
71-
y: .zero,
72-
width: 100,
73-
height: 100)
74-
75-
controller.editorOverscroll = 0
76-
controller.contentInsets = nil
77-
controller.reloadUI()
78-
79-
// editorOverscroll: 0
80-
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0)
81-
82-
controller.editorOverscroll = 0.5
83-
controller.reloadUI()
84-
85-
// editorOverscroll: 0.5
86-
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 50.0)
87-
88-
controller.editorOverscroll = 1.0
89-
controller.reloadUI()
90-
91-
// editorOverscroll: 1.0
92-
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 87.0)
93-
}
94-
9566
// MARK: Insets
9667

9768
func test_editorInsets() throws {

0 commit comments

Comments
 (0)