diff --git a/Sources/CodeEditSourceEditor/Controller/TextViewController+IndentLines.swift b/Sources/CodeEditSourceEditor/Controller/TextViewController+IndentLines.swift index 8d690b76f..cbe6f4be9 100644 --- a/Sources/CodeEditSourceEditor/Controller/TextViewController+IndentLines.swift +++ b/Sources/CodeEditSourceEditor/Controller/TextViewController+IndentLines.swift @@ -1,12 +1,12 @@ // // TextViewController+IndentLines.swift -// +// CodeEditTextView // // Created by Ludwig, Tom on 11.09.24. // -import CodeEditTextView import AppKit +import CodeEditTextView extension TextViewController { /// Handles indentation and unindentation @@ -23,7 +23,7 @@ extension TextViewController { guard !cursorPositions.isEmpty else { return } textView.undoManager?.beginUndoGrouping() -for cursorPosition in self.cursorPositions.reversed() { + for cursorPosition in self.cursorPositions.reversed() { // get lineindex, i.e line-numbers+1 guard let lineIndexes = getHighlightedLines(for: cursorPosition.range) else { continue } diff --git a/Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift b/Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift index cd12c07a5..ea1dacd36 100644 --- a/Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift +++ b/Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift @@ -67,6 +67,6 @@ extension TextViewController { } else { scrollView.automaticallyAdjustsContentInsets = true } - scrollView.contentInsets.bottom = (contentInsets?.bottom ?? 0) + bottomContentInsets + scrollView.contentInsets.bottom = contentInsets?.bottom ?? 0 } } diff --git a/Sources/CodeEditSourceEditor/Controller/TextViewController.swift b/Sources/CodeEditSourceEditor/Controller/TextViewController.swift index a8e275e49..926c8ab10 100644 --- a/Sources/CodeEditSourceEditor/Controller/TextViewController.swift +++ b/Sources/CodeEditSourceEditor/Controller/TextViewController.swift @@ -104,7 +104,11 @@ public class TextViewController: NSViewController { /// /// Measured in a percentage of the view's total height, meaning a `0.3` value will result in overscroll /// of 1/3 of the view. - public var editorOverscroll: CGFloat + public var editorOverscroll: CGFloat { + didSet { + textView.overscrollAmount = editorOverscroll + } + } /// Whether the code editor should use the theme background color or be transparent public var useThemeBackground: Bool @@ -183,18 +187,6 @@ public class TextViewController: NSViewController { internal var cancellables = Set() - /// ScrollView's bottom inset using as editor overscroll - package var bottomContentInsets: CGFloat { - let height = view.frame.height - var inset = editorOverscroll * height - - if height - inset < font.lineHeight * lineHeightMultiple { - inset = height - font.lineHeight * lineHeightMultiple - } - - return max(inset, .zero) - } - /// The trailing inset for the editor. Grows when line wrapping is disabled. package var textViewTrailingInset: CGFloat { // See https://github.com/CodeEditApp/CodeEditTextView/issues/66 diff --git a/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift b/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift index ac7f4ecac..639c1a885 100644 --- a/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift +++ b/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift @@ -66,30 +66,19 @@ final class TextViewControllerTests: XCTestCase { // MARK: Overscroll func test_editorOverScroll() throws { - let scrollView = try XCTUnwrap(controller.view as? NSScrollView) - scrollView.frame = .init(x: .zero, - y: .zero, - width: 100, - height: 100) - controller.editorOverscroll = 0 - controller.contentInsets = nil - controller.reloadUI() // editorOverscroll: 0 - XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0) + XCTAssertEqual(controller.textView.overscrollAmount, 0) controller.editorOverscroll = 0.5 - controller.reloadUI() // editorOverscroll: 0.5 - XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 50.0) + XCTAssertEqual(controller.textView.overscrollAmount, 0.5) controller.editorOverscroll = 1.0 - controller.reloadUI() - // editorOverscroll: 1.0 - XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 87.0) + XCTAssertEqual(controller.textView.overscrollAmount, 1.0) } // MARK: Insets @@ -135,10 +124,10 @@ final class TextViewControllerTests: XCTestCase { // contentInsets: 16 // editorOverscroll: 0.5 controller.contentInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) - controller.editorOverscroll = 0.5 + controller.editorOverscroll = 0.5 // Should be ignored controller.reloadUI() - try assertInsetsEqual(scrollView.contentInsets, NSEdgeInsets(top: 16, left: 16, bottom: 16 + 50, right: 16)) + try assertInsetsEqual(scrollView.contentInsets, NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)) XCTAssertEqual(controller.gutterView.frame.origin.y, -16) }