Skip to content

Commit f2cffd4

Browse files
committed
Add controllerDidAppear/Disappear APIs
1 parent 7256a2d commit f2cffd4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sources/CodeEditSourceEditor/Controller/TextViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)