Skip to content

Commit 99779fa

Browse files
Improve Public API (#339)
### Description Makes some slight adjustments to the public API. - Adds new, optional, `controllerDidAppear/Disappear` methods to text coordinators. - Makes the textView and scrollView properties on the text view controller have `public` getters. ### Related Issues Related to issues brought up on Discord. ### 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 No UI Changes
1 parent 1c87221 commit 99779fa

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Sources/CodeEditSourceEditor/Controller/TextViewController.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class TextViewController: NSViewController {
2424

2525
weak var findViewController: FindViewController?
2626

27-
var scrollView: NSScrollView!
28-
var textView: TextView!
27+
internal(set) public var scrollView: NSScrollView!
28+
internal(set) public var textView: TextView!
2929
var gutterView: GutterView!
3030
var minimapView: MinimapView!
3131

@@ -256,6 +256,16 @@ public class TextViewController: NSViewController {
256256
minimapView.layout()
257257
}
258258

259+
override public func viewDidAppear() {
260+
super.viewDidAppear()
261+
textCoordinators.forEach { $0.val?.controllerDidAppear(controller: self) }
262+
}
263+
264+
override public func viewDidDisappear() {
265+
super.viewDidDisappear()
266+
textCoordinators.forEach { $0.val?.controllerDidDisappear(controller: self) }
267+
}
268+
259269
deinit {
260270
if let highlighter {
261271
textView.removeStorageDelegate(highlighter)

Sources/CodeEditSourceEditor/TextViewCoordinator/TextViewCoordinator.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public protocol TextViewCoordinator: AnyObject {
2626
/// dereferenced when ``TextViewCoordinator/destroy()-9nzfl`` is called.
2727
func prepareCoordinator(controller: TextViewController)
2828

29+
/// Called when the controller's `viewDidAppear` method is called by AppKit.
30+
/// - Parameter controller: The text view controller that did appear.
31+
func controllerDidAppear(controller: TextViewController)
32+
33+
/// Called when the controller's `viewDidDisappear` method is called by AppKit.
34+
/// - Parameter controller: The text view controller that did disappear.
35+
func controllerDidDisappear(controller: TextViewController)
36+
2937
/// Called when the text view's text changed.
3038
/// - Parameter controller: The text controller.
3139
func textViewDidChangeText(controller: TextViewController)
@@ -40,6 +48,8 @@ public protocol TextViewCoordinator: AnyObject {
4048

4149
/// Default implementations
4250
public extension TextViewCoordinator {
51+
func controllerDidAppear(controller: TextViewController) { }
52+
func controllerDidDisappear(controller: TextViewController) { }
4353
func textViewDidChangeText(controller: TextViewController) { }
4454
func textViewDidChangeSelection(controller: TextViewController, newPositions: [CursorPosition]) { }
4555
func destroy() { }

0 commit comments

Comments
 (0)