Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Sources/CodeEditSourceEditor/Controller/TextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class TextViewController: NSViewController {

weak var findViewController: FindViewController?

var scrollView: NSScrollView!
var textView: TextView!
internal(set) public var scrollView: NSScrollView!
internal(set) public var textView: TextView!
var gutterView: GutterView!
var minimapView: MinimapView!

Expand Down Expand Up @@ -256,6 +256,16 @@ public class TextViewController: NSViewController {
minimapView.layout()
}

override public func viewDidAppear() {
super.viewDidAppear()
textCoordinators.forEach { $0.val?.controllerDidAppear(controller: self) }
}

override public func viewDidDisappear() {
super.viewDidDisappear()
textCoordinators.forEach { $0.val?.controllerDidDisappear(controller: self) }
}

deinit {
if let highlighter {
textView.removeStorageDelegate(highlighter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public protocol TextViewCoordinator: AnyObject {
/// dereferenced when ``TextViewCoordinator/destroy()-9nzfl`` is called.
func prepareCoordinator(controller: TextViewController)

/// Called when the controller's `viewDidAppear` method is called by AppKit.
/// - Parameter controller: The text view controller that did appear.
func controllerDidAppear(controller: TextViewController)

/// Called when the controller's `viewDidDisappear` method is called by AppKit.
/// - Parameter controller: The text view controller that did disappear.
func controllerDidDisappear(controller: TextViewController)

/// Called when the text view's text changed.
/// - Parameter controller: The text controller.
func textViewDidChangeText(controller: TextViewController)
Expand All @@ -40,6 +48,8 @@ public protocol TextViewCoordinator: AnyObject {

/// Default implementations
public extension TextViewCoordinator {
func controllerDidAppear(controller: TextViewController) { }
func controllerDidDisappear(controller: TextViewController) { }
func textViewDidChangeText(controller: TextViewController) { }
func textViewDidChangeSelection(controller: TextViewController, newPositions: [CursorPosition]) { }
func destroy() { }
Expand Down