From 53dc8d833379cec1e411456b33fa7fbfb09a16fa Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Mon, 2 Jan 2023 18:11:14 +0100 Subject: [PATCH 01/10] update dependencies - CodeEditLanguages to 0.1.5 --- Package.resolved | 4 ++-- Package.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.resolved b/Package.resolved index 47858a7bf..490c7ede3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/CodeEditApp/CodeEditLanguages.git", "state" : { - "revision" : "6890198b9738e1b60c867294eee446aca85a9d8b", - "version" : "0.1.4" + "revision" : "9f107a5d9a4da49075dcdc288b5e69527a9e5a64", + "version" : "0.1.5" } }, { diff --git a/Package.swift b/Package.swift index 0bc387bb7..55e7bfdc1 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,7 @@ let package = Package( ), .package( url: "https://github.com/CodeEditApp/CodeEditLanguages.git", - exact: "0.1.4" + exact: "0.1.5" ), ], targets: [ From bfe2746d9d51612781ff61a4621a0c77e776ff5f Mon Sep 17 00:00:00 2001 From: Austin Condiff Date: Tue, 6 Dec 2022 13:30:09 -0600 Subject: [PATCH 02/10] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5fb13510a..e4113c1b9 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ Licensed under the [MIT license](https://github.com/CodeEditApp/CodeEdit/blob/ma

CodeEditLanguages

+ + + +

CodeEdit CLI

+
+ From 95878e9c3be3d495e9f7d93216375e25e42c0cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Wed, 7 Dec 2022 14:11:40 +0300 Subject: [PATCH 03/10] Add editor over scroll --- Sources/CodeEditTextView/CodeEditTextView.swift | 7 ++++++- Sources/CodeEditTextView/STTextViewController.swift | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Sources/CodeEditTextView/CodeEditTextView.swift b/Sources/CodeEditTextView/CodeEditTextView.swift index da3b7d41a..c03f700fc 100644 --- a/Sources/CodeEditTextView/CodeEditTextView.swift +++ b/Sources/CodeEditTextView/CodeEditTextView.swift @@ -27,6 +27,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { font: Binding, tabWidth: Binding, lineHeight: Binding, + overScrollLineCount: Binding = .constant(0), cursorPosition: Published<(Int, Int)>.Publisher? = nil ) { self._text = text @@ -35,6 +36,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { self._font = font self._tabWidth = tabWidth self._lineHeight = lineHeight + self._overScrollLineCount = overScrollLineCount self.cursorPosition = cursorPosition } @@ -44,6 +46,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { @Binding private var font: NSFont @Binding private var tabWidth: Int @Binding private var lineHeight: Double + @Binding private var overScrollLineCount: Int private var cursorPosition: Published<(Int, Int)>.Publisher? public typealias NSViewControllerType = STTextViewController @@ -55,7 +58,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable { font: font, theme: theme, tabWidth: tabWidth, - cursorPosition: cursorPosition + cursorPosition: cursorPosition, + overScrollLineCount: overScrollLineCount ) controller.lineHeightMultiple = lineHeight return controller @@ -67,6 +71,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { controller.theme = theme controller.tabWidth = tabWidth controller.lineHeightMultiple = lineHeight + controller.overScrollLineCount = overScrollLineCount controller.reloadUI() return } diff --git a/Sources/CodeEditTextView/STTextViewController.swift b/Sources/CodeEditTextView/STTextViewController.swift index 8f1539c92..470937e68 100644 --- a/Sources/CodeEditTextView/STTextViewController.swift +++ b/Sources/CodeEditTextView/STTextViewController.swift @@ -42,6 +42,9 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt /// The font to use in the `textView` public var font: NSFont + /// The overScrollLineCount to use for the textView over scroll + public var overScrollLineCount: Int + // MARK: - Highlighting internal var highlighter: Highlighter? @@ -55,7 +58,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt font: NSFont, theme: EditorTheme, tabWidth: Int, - cursorPosition: Published<(Int, Int)>.Publisher? = nil + cursorPosition: Published<(Int, Int)>.Publisher? = nil, + overScrollLineCount: Int ) { self.text = text self.language = language @@ -63,6 +67,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt self.theme = theme self.tabWidth = tabWidth self.cursorPosition = cursorPosition + self.overScrollLineCount = overScrollLineCount super.init(nibName: nil, bundle: nil) } @@ -112,6 +117,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt scrollView.translatesAutoresizingMaskIntoConstraints = false + scrollView.contentInsets.bottom = Double(overScrollLineCount) * lineHeight + self.view = scrollView NSLayoutConstraint.activate([ @@ -182,6 +189,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt rulerView?.separatorColor = theme.invisibles rulerView?.baselineOffset = baselineOffset + (view as? NSScrollView)?.contentInsets.bottom = Double(overScrollLineCount) * lineHeight + setStandardAttributes() } From 493641856a489b9a0fc606a84d92840b6cdc682a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Wed, 7 Dec 2022 14:11:53 +0300 Subject: [PATCH 04/10] Add editor over scroll unit tests --- .../STTextViewControllerTests.swift | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift b/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift index 8da553545..c31babe85 100644 --- a/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift +++ b/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift @@ -32,7 +32,8 @@ final class STTextViewControllerTests: XCTestCase { language: .default, font: .monospacedSystemFont(ofSize: 11, weight: .medium), theme: theme, - tabWidth: 4 + tabWidth: 4, + overScrollLineCount: 5 ) } @@ -60,4 +61,25 @@ final class STTextViewControllerTests: XCTestCase { XCTAssertEqual(color4, NSColor.textColor) } + func test_editorOverScroll() throws { + let scrollView = try XCTUnwrap(controller.view as? NSScrollView) + + // overScrollLineCount: 5, lineHeight: 13 + XCTAssertEqual(scrollView.contentInsets.bottom, 65) + } + + + func test_editorOverScroll_AfterUpdate() throws { + let scrollView = try XCTUnwrap(controller.view as? NSScrollView) + + // overScrollLineCount: 5, lineHeight: 13 + XCTAssertEqual(scrollView.contentInsets.bottom, 65) + + controller.overScrollLineCount = 10 + controller.reloadUI() + + // overScrollLineCount: 10, lineHeight: 13 + XCTAssertEqual(scrollView.contentInsets.bottom, 130) + } + } From 0ebf841913869bcd2792e2fb639325a39a2f8bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Wed, 7 Dec 2022 20:55:15 +0300 Subject: [PATCH 05/10] Change overscroll strategy --- .../CodeEditTextView/CodeEditTextView.swift | 10 +++---- .../STTextViewController.swift | 27 ++++++++++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Sources/CodeEditTextView/CodeEditTextView.swift b/Sources/CodeEditTextView/CodeEditTextView.swift index c03f700fc..108c95b00 100644 --- a/Sources/CodeEditTextView/CodeEditTextView.swift +++ b/Sources/CodeEditTextView/CodeEditTextView.swift @@ -27,7 +27,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { font: Binding, tabWidth: Binding, lineHeight: Binding, - overScrollLineCount: Binding = .constant(0), + overScrollRatio: Binding = .constant(0.0), cursorPosition: Published<(Int, Int)>.Publisher? = nil ) { self._text = text @@ -36,7 +36,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { self._font = font self._tabWidth = tabWidth self._lineHeight = lineHeight - self._overScrollLineCount = overScrollLineCount + self._overScrollRatio = overScrollRatio self.cursorPosition = cursorPosition } @@ -46,7 +46,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { @Binding private var font: NSFont @Binding private var tabWidth: Int @Binding private var lineHeight: Double - @Binding private var overScrollLineCount: Int + @Binding private var overScrollRatio: Double private var cursorPosition: Published<(Int, Int)>.Publisher? public typealias NSViewControllerType = STTextViewController @@ -59,7 +59,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { theme: theme, tabWidth: tabWidth, cursorPosition: cursorPosition, - overScrollLineCount: overScrollLineCount + overScrollRatio: overScrollRatio ) controller.lineHeightMultiple = lineHeight return controller @@ -71,7 +71,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { controller.theme = theme controller.tabWidth = tabWidth controller.lineHeightMultiple = lineHeight - controller.overScrollLineCount = overScrollLineCount + controller.overScrollRatio = overScrollRatio controller.reloadUI() return } diff --git a/Sources/CodeEditTextView/STTextViewController.swift b/Sources/CodeEditTextView/STTextViewController.swift index 470937e68..e5e9acf92 100644 --- a/Sources/CodeEditTextView/STTextViewController.swift +++ b/Sources/CodeEditTextView/STTextViewController.swift @@ -43,7 +43,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt public var font: NSFont /// The overScrollLineCount to use for the textView over scroll - public var overScrollLineCount: Int + public var overScrollRatio: Double // MARK: - Highlighting @@ -59,7 +59,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt theme: EditorTheme, tabWidth: Int, cursorPosition: Published<(Int, Int)>.Publisher? = nil, - overScrollLineCount: Int + overScrollRatio: Double ) { self.text = text self.language = language @@ -67,7 +67,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt self.theme = theme self.tabWidth = tabWidth self.cursorPosition = cursorPosition - self.overScrollLineCount = overScrollLineCount + self.overScrollRatio = overScrollRatio super.init(nibName: nil, bundle: nil) } @@ -117,8 +117,6 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt scrollView.translatesAutoresizingMaskIntoConstraints = false - scrollView.contentInsets.bottom = Double(overScrollLineCount) * lineHeight - self.view = scrollView NSLayoutConstraint.activate([ @@ -143,6 +141,11 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt self.cursorPositionCancellable = self.cursorPosition?.sink(receiveValue: { value in self.setCursorPosition(value) }) + + NotificationCenter.default.addObserver(forName: NSWindow.didResizeNotification, object: nil, queue: .main) { [weak self] _ in + guard let self = self else { return } + (self.view as? NSScrollView)?.contentView.contentInsets.bottom = self.bottomContentInsets + } } internal func setUpHighlighting() { @@ -176,6 +179,18 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt return paragraph } + /// ScrollView's bottom inset using as editor overscroll + private var bottomContentInsets: CGFloat { + let height = view.frame.height + var inset = overScrollRatio * height + + if height - inset < lineHeight { + inset = height - lineHeight + } + + return max(inset, .zero) + } + /// Reloads the UI to apply changes to ``STTextViewController/font``, ``STTextViewController/theme``, ... internal func reloadUI() { textView?.font = font @@ -189,7 +204,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt rulerView?.separatorColor = theme.invisibles rulerView?.baselineOffset = baselineOffset - (view as? NSScrollView)?.contentInsets.bottom = Double(overScrollLineCount) * lineHeight + (view as? NSScrollView)?.contentView.contentInsets.bottom = bottomContentInsets setStandardAttributes() } From 2dfc69dcdc81b2dd403fa82673590a38cd5287cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Wed, 7 Dec 2022 20:55:26 +0300 Subject: [PATCH 06/10] Update unit tests --- .../STTextViewControllerTests.swift | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift b/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift index c31babe85..48df9e9b5 100644 --- a/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift +++ b/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift @@ -33,7 +33,7 @@ final class STTextViewControllerTests: XCTestCase { font: .monospacedSystemFont(ofSize: 11, weight: .medium), theme: theme, tabWidth: 4, - overScrollLineCount: 5 + overScrollRatio: 0.5 ) } @@ -63,23 +63,32 @@ final class STTextViewControllerTests: XCTestCase { func test_editorOverScroll() throws { let scrollView = try XCTUnwrap(controller.view as? NSScrollView) + scrollView.frame = .init(x: .zero, + y: .zero, + width: 100, + height: 100) - // overScrollLineCount: 5, lineHeight: 13 - XCTAssertEqual(scrollView.contentInsets.bottom, 65) - } - + // overScrollRatio: 0 + XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0) - func test_editorOverScroll_AfterUpdate() throws { - let scrollView = try XCTUnwrap(controller.view as? NSScrollView) + controller.overScrollRatio = 0.5 + controller.reloadUI() - // overScrollLineCount: 5, lineHeight: 13 - XCTAssertEqual(scrollView.contentInsets.bottom, 65) + // overScrollRatio: 0.5 + XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 50.0) - controller.overScrollLineCount = 10 + controller.overScrollRatio = 1.0 controller.reloadUI() - // overScrollLineCount: 10, lineHeight: 13 - XCTAssertEqual(scrollView.contentInsets.bottom, 130) + // overScrollRatio: 1.0 + XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 87.0) } + func test_editorOverScroll_ZeroCondition() throws { + let scrollView = try XCTUnwrap(controller.view as? NSScrollView) + scrollView.frame = .zero + + // overScrollRatio: 0 + XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0) + } } From 8f813af6f8cd28bdde8cf5390dec64aa4650dabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Thu, 8 Dec 2022 00:56:38 +0300 Subject: [PATCH 07/10] Update documentation --- README.md | 4 +++- .../CodeEditTextView/Documentation.docc/CodeEditTextView.md | 4 +++- .../Documentation.docc/STTextViewController.md | 1 + Sources/CodeEditTextView/STTextViewController.swift | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e4113c1b9..681d043eb 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ struct ContentView: View { @State var font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular) @State var tabWidth = 4 @State var lineHeight = 1.2 + @State var overScrollRatio = 0.3 var body: some View { CodeEditTextView( @@ -52,7 +53,8 @@ struct ContentView: View { theme: $theme, font: $font, tabWidth: $tabWidth, - lineHeight: $lineHeight + lineHeight: $lineHeight, + overScrollRatio: $overScrollRatio ) } } diff --git a/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md b/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md index 9f069aacb..eb30c6831 100644 --- a/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md +++ b/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md @@ -12,6 +12,7 @@ struct ContentView: View { @State var font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular) @State var tabWidth = 4 @State var lineHeight = 1.2 + @State var overScrollRatio = 0.3 var body: some View { CodeEditTextView( @@ -20,7 +21,8 @@ struct ContentView: View { theme: $theme, font: $font, tabWidth: $tabWidth, - lineHeight: $lineHeight + lineHeight: $lineHeight, + overScrollRatio: $overScrollRatio ) } } diff --git a/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md b/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md index 208800651..c6d79eaa2 100644 --- a/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md +++ b/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md @@ -10,3 +10,4 @@ - ``font`` - ``tabWidth`` - ``lineHeightMultiple`` +- ``overScrollRatio`` diff --git a/Sources/CodeEditTextView/STTextViewController.swift b/Sources/CodeEditTextView/STTextViewController.swift index e5e9acf92..51a12b62a 100644 --- a/Sources/CodeEditTextView/STTextViewController.swift +++ b/Sources/CodeEditTextView/STTextViewController.swift @@ -42,7 +42,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt /// The font to use in the `textView` public var font: NSFont - /// The overScrollLineCount to use for the textView over scroll + /// The overScrollRatio to use for the textView over scroll public var overScrollRatio: Double // MARK: - Highlighting From 8d3035925e78a7994cc6241be86703b10e575a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Thu, 8 Dec 2022 01:08:59 +0300 Subject: [PATCH 08/10] Fix SwiftLint warnings --- Sources/CodeEditTextView/STTextViewController.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/CodeEditTextView/STTextViewController.swift b/Sources/CodeEditTextView/STTextViewController.swift index 51a12b62a..4902f3ea5 100644 --- a/Sources/CodeEditTextView/STTextViewController.swift +++ b/Sources/CodeEditTextView/STTextViewController.swift @@ -141,11 +141,6 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt self.cursorPositionCancellable = self.cursorPosition?.sink(receiveValue: { value in self.setCursorPosition(value) }) - - NotificationCenter.default.addObserver(forName: NSWindow.didResizeNotification, object: nil, queue: .main) { [weak self] _ in - guard let self = self else { return } - (self.view as? NSScrollView)?.contentView.contentInsets.bottom = self.bottomContentInsets - } } internal func setUpHighlighting() { @@ -162,6 +157,13 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt public override func viewDidLoad() { super.viewDidLoad() + + NotificationCenter.default.addObserver(forName: NSWindow.didResizeNotification, + object: nil, + queue: .main) { [weak self] _ in + guard let self = self else { return } + (self.view as? NSScrollView)?.contentView.contentInsets.bottom = self.bottomContentInsets + } } public override func viewDidAppear() { From 238b7b42b90e7bbb701d36eaf63970bcff073818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Thu, 8 Dec 2022 09:12:45 +0300 Subject: [PATCH 09/10] Fix DocC comment --- Sources/CodeEditTextView/CodeEditTextView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/CodeEditTextView/CodeEditTextView.swift b/Sources/CodeEditTextView/CodeEditTextView.swift index 108c95b00..2297f79eb 100644 --- a/Sources/CodeEditTextView/CodeEditTextView.swift +++ b/Sources/CodeEditTextView/CodeEditTextView.swift @@ -20,6 +20,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { /// - font: The default font /// - tabWidth: The tab width /// - lineHeight: The line height multiplier (e.g. `1.2`) + /// - overScrollRatio: The ratio for overscroll, between 0-1 (default: `0.0`) public init( _ text: Binding, language: CodeLanguage, From add1c512088251e8c4e7cf0a3b4e4f4296f9e3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=96zg=C3=BCl?= Date: Fri, 9 Dec 2022 12:22:37 +0300 Subject: [PATCH 10/10] Rename variables --- README.md | 4 ++-- Sources/CodeEditTextView/CodeEditTextView.swift | 12 ++++++------ .../Documentation.docc/CodeEditTextView.md | 4 ++-- .../Documentation.docc/STTextViewController.md | 2 +- .../CodeEditTextView/STTextViewController.swift | 10 +++++----- .../STTextViewControllerTests.swift | 14 +++++++------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 681d043eb..30dd8c2c1 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ struct ContentView: View { @State var font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular) @State var tabWidth = 4 @State var lineHeight = 1.2 - @State var overScrollRatio = 0.3 + @State var editorOverscroll = 0.3 var body: some View { CodeEditTextView( @@ -54,7 +54,7 @@ struct ContentView: View { font: $font, tabWidth: $tabWidth, lineHeight: $lineHeight, - overScrollRatio: $overScrollRatio + editorOverscroll: $editorOverscroll ) } } diff --git a/Sources/CodeEditTextView/CodeEditTextView.swift b/Sources/CodeEditTextView/CodeEditTextView.swift index 2297f79eb..fd02c5dce 100644 --- a/Sources/CodeEditTextView/CodeEditTextView.swift +++ b/Sources/CodeEditTextView/CodeEditTextView.swift @@ -20,7 +20,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { /// - font: The default font /// - tabWidth: The tab width /// - lineHeight: The line height multiplier (e.g. `1.2`) - /// - overScrollRatio: The ratio for overscroll, between 0-1 (default: `0.0`) + /// - editorOverscroll: The percentage for overscroll, between 0-1 (default: `0.0`) public init( _ text: Binding, language: CodeLanguage, @@ -28,7 +28,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { font: Binding, tabWidth: Binding, lineHeight: Binding, - overScrollRatio: Binding = .constant(0.0), + editorOverscroll: Binding = .constant(0.0), cursorPosition: Published<(Int, Int)>.Publisher? = nil ) { self._text = text @@ -37,7 +37,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { self._font = font self._tabWidth = tabWidth self._lineHeight = lineHeight - self._overScrollRatio = overScrollRatio + self._editorOverscroll = editorOverscroll self.cursorPosition = cursorPosition } @@ -47,7 +47,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { @Binding private var font: NSFont @Binding private var tabWidth: Int @Binding private var lineHeight: Double - @Binding private var overScrollRatio: Double + @Binding private var editorOverscroll: Double private var cursorPosition: Published<(Int, Int)>.Publisher? public typealias NSViewControllerType = STTextViewController @@ -60,7 +60,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { theme: theme, tabWidth: tabWidth, cursorPosition: cursorPosition, - overScrollRatio: overScrollRatio + editorOverscroll: editorOverscroll ) controller.lineHeightMultiple = lineHeight return controller @@ -72,7 +72,7 @@ public struct CodeEditTextView: NSViewControllerRepresentable { controller.theme = theme controller.tabWidth = tabWidth controller.lineHeightMultiple = lineHeight - controller.overScrollRatio = overScrollRatio + controller.editorOverscroll = editorOverscroll controller.reloadUI() return } diff --git a/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md b/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md index eb30c6831..c8512125b 100644 --- a/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md +++ b/Sources/CodeEditTextView/Documentation.docc/CodeEditTextView.md @@ -12,7 +12,7 @@ struct ContentView: View { @State var font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular) @State var tabWidth = 4 @State var lineHeight = 1.2 - @State var overScrollRatio = 0.3 + @State var editorOverscroll = 0.3 var body: some View { CodeEditTextView( @@ -22,7 +22,7 @@ struct ContentView: View { font: $font, tabWidth: $tabWidth, lineHeight: $lineHeight, - overScrollRatio: $overScrollRatio + editorOverscroll: $editorOverscroll ) } } diff --git a/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md b/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md index c6d79eaa2..19d1c7909 100644 --- a/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md +++ b/Sources/CodeEditTextView/Documentation.docc/STTextViewController.md @@ -10,4 +10,4 @@ - ``font`` - ``tabWidth`` - ``lineHeightMultiple`` -- ``overScrollRatio`` +- ``editorOverscroll`` diff --git a/Sources/CodeEditTextView/STTextViewController.swift b/Sources/CodeEditTextView/STTextViewController.swift index 4902f3ea5..fcfb51870 100644 --- a/Sources/CodeEditTextView/STTextViewController.swift +++ b/Sources/CodeEditTextView/STTextViewController.swift @@ -42,8 +42,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt /// The font to use in the `textView` public var font: NSFont - /// The overScrollRatio to use for the textView over scroll - public var overScrollRatio: Double + /// The editorOverscroll to use for the textView over scroll + public var editorOverscroll: Double // MARK: - Highlighting @@ -59,7 +59,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt theme: EditorTheme, tabWidth: Int, cursorPosition: Published<(Int, Int)>.Publisher? = nil, - overScrollRatio: Double + editorOverscroll: Double ) { self.text = text self.language = language @@ -67,7 +67,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt self.theme = theme self.tabWidth = tabWidth self.cursorPosition = cursorPosition - self.overScrollRatio = overScrollRatio + self.editorOverscroll = editorOverscroll super.init(nibName: nil, bundle: nil) } @@ -184,7 +184,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt /// ScrollView's bottom inset using as editor overscroll private var bottomContentInsets: CGFloat { let height = view.frame.height - var inset = overScrollRatio * height + var inset = editorOverscroll * height if height - inset < lineHeight { inset = height - lineHeight diff --git a/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift b/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift index 48df9e9b5..03a9348fb 100644 --- a/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift +++ b/Tests/CodeEditTextViewTests/STTextViewControllerTests.swift @@ -33,7 +33,7 @@ final class STTextViewControllerTests: XCTestCase { font: .monospacedSystemFont(ofSize: 11, weight: .medium), theme: theme, tabWidth: 4, - overScrollRatio: 0.5 + editorOverscroll: 0.5 ) } @@ -68,19 +68,19 @@ final class STTextViewControllerTests: XCTestCase { width: 100, height: 100) - // overScrollRatio: 0 + // editorOverscroll: 0 XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0) - controller.overScrollRatio = 0.5 + controller.editorOverscroll = 0.5 controller.reloadUI() - // overScrollRatio: 0.5 + // editorOverscroll: 0.5 XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 50.0) - controller.overScrollRatio = 1.0 + controller.editorOverscroll = 1.0 controller.reloadUI() - // overScrollRatio: 1.0 + // editorOverscroll: 1.0 XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 87.0) } @@ -88,7 +88,7 @@ final class STTextViewControllerTests: XCTestCase { let scrollView = try XCTUnwrap(controller.view as? NSScrollView) scrollView.frame = .zero - // overScrollRatio: 0 + // editorOverscroll: 0 XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0) } }