Skip to content

Commit 511f9da

Browse files
Merge branch 'main' into feat/editor-state-publishers
2 parents ec5d847 + 99779fa commit 511f9da

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
@@ -28,8 +28,8 @@ public class TextViewController: NSViewController {
2828

2929
weak var findViewController: FindViewController?
3030

31-
var scrollView: NSScrollView!
32-
var textView: TextView!
31+
internal(set) public var scrollView: NSScrollView!
32+
internal(set) public var textView: TextView!
3333
var gutterView: GutterView!
3434
var minimapView: MinimapView!
3535

@@ -260,6 +260,16 @@ public class TextViewController: NSViewController {
260260
minimapView.layout()
261261
}
262262

263+
override public func viewDidAppear() {
264+
super.viewDidAppear()
265+
textCoordinators.forEach { $0.val?.controllerDidAppear(controller: self) }
266+
}
267+
268+
override public func viewDidDisappear() {
269+
super.viewDidDisappear()
270+
textCoordinators.forEach { $0.val?.controllerDidDisappear(controller: self) }
271+
}
272+
263273
deinit {
264274
if let highlighter {
265275
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)