Skip to content

Commit 56acf85

Browse files
committed
Merge branch 'main' into feat/in-doc-search
2 parents 1dc6c3b + 603e89c commit 56acf85

File tree

5 files changed

+16
-32
lines changed

5 files changed

+16
-32
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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
@@ -74,6 +74,6 @@ extension TextViewController {
7474
} else {
7575
scrollView.automaticallyAdjustsContentInsets = true
7676
}
77-
scrollView.contentInsets.bottom = (contentInsets?.bottom ?? 0) + bottomContentInsets
77+
scrollView.contentInsets.bottom = contentInsets?.bottom ?? 0
7878
}
7979
}

Sources/CodeEditSourceEditor/Controller/TextViewController.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ public class TextViewController: NSViewController {
115115
///
116116
/// Measured in a percentage of the view's total height, meaning a `0.3` value will result in overscroll
117117
/// of 1/3 of the view.
118-
public var editorOverscroll: CGFloat
118+
public var editorOverscroll: CGFloat {
119+
didSet {
120+
textView.overscrollAmount = editorOverscroll
121+
}
122+
}
119123

120124
/// Whether the code editor should use the theme background color or be transparent
121125
public var useThemeBackground: Bool
@@ -198,18 +202,6 @@ public class TextViewController: NSViewController {
198202

199203
internal var cancellables = Set<AnyCancellable>()
200204

201-
/// ScrollView's bottom inset using as editor overscroll
202-
package var bottomContentInsets: CGFloat {
203-
let height = view.frame.height
204-
var inset = editorOverscroll * height
205-
206-
if height - inset < font.lineHeight * lineHeightMultiple {
207-
inset = height - font.lineHeight * lineHeightMultiple
208-
}
209-
210-
return max(inset, .zero)
211-
}
212-
213205
/// The trailing inset for the editor. Grows when line wrapping is disabled.
214206
package var textViewTrailingInset: CGFloat {
215207
// See https://github.com/CodeEditApp/CodeEditTextView/issues/66

Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,19 @@ final class TextViewControllerTests: XCTestCase {
6666
// MARK: Overscroll
6767

6868
func test_editorOverScroll() throws {
69-
let scrollView = try XCTUnwrap(controller.scrollView)
70-
scrollView.frame = .init(x: .zero, y: .zero, width: 100, height: 100)
71-
7269
controller.editorOverscroll = 0
73-
controller.contentInsets = nil
74-
controller.reloadUI()
7570

7671
// editorOverscroll: 0
77-
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0)
72+
XCTAssertEqual(controller.textView.overscrollAmount, 0)
7873

7974
controller.editorOverscroll = 0.5
80-
controller.reloadUI()
8175

8276
// editorOverscroll: 0.5
83-
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 50.0)
77+
XCTAssertEqual(controller.textView.overscrollAmount, 0.5)
8478

8579
controller.editorOverscroll = 1.0
86-
controller.reloadUI()
8780

88-
// editorOverscroll: 1.0
89-
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 87.0)
81+
XCTAssertEqual(controller.textView.overscrollAmount, 1.0)
9082
}
9183

9284
// MARK: Insets
@@ -132,10 +124,10 @@ final class TextViewControllerTests: XCTestCase {
132124
// contentInsets: 16
133125
// editorOverscroll: 0.5
134126
controller.contentInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
135-
controller.editorOverscroll = 0.5
127+
controller.editorOverscroll = 0.5 // Should be ignored
136128
controller.reloadUI()
137129

138-
try assertInsetsEqual(scrollView.contentInsets, NSEdgeInsets(top: 16, left: 16, bottom: 16 + 50, right: 16))
130+
try assertInsetsEqual(scrollView.contentInsets, NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16))
139131
XCTAssertEqual(controller.gutterView.frame.origin.y, -16)
140132
}
141133

0 commit comments

Comments
 (0)