File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
TextLayoutManager/TextAttachments Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ public final class TextAttachmentManager {
1717 weak var layoutManager : TextLayoutManager ?
1818 private var selectionObserver : ( any NSObjectProtocol ) ?
1919
20+ public weak var delegate : TextAttachmentManagerDelegate ?
21+
2022 /// Adds a new attachment, keeping `orderedAttachments` sorted by range.location.
2123 /// If two attachments overlap, the layout phase will later ignore the one with the higher start.
2224 /// - Complexity: `O(n log(n))` due to array insertion. Could be improved with a binary tree.
@@ -47,6 +49,8 @@ public final class TextAttachmentManager {
4749 }
4850
4951 layoutManager? . setNeedsLayout ( )
52+
53+ delegate? . textAttachmentDidAdd ( attachment. attachment, for: range)
5054 }
5155
5256 /// Removes an attachment and invalidates layout for the removed range.
@@ -62,6 +66,9 @@ public final class TextAttachmentManager {
6266
6367 let attachment = orderedAttachments. remove ( at: index)
6468 layoutManager? . invalidateLayoutForRange ( attachment. range)
69+
70+ delegate? . textAttachmentDidRemove ( attachment. attachment, for: attachment. range)
71+
6572 return attachment
6673 }
6774
Original file line number Diff line number Diff line change 1+ //
2+ // TextAttachmentManagerDelegate.swift
3+ // CodeEditTextView
4+ //
5+ // Created by Khan Winter on 6/25/25.
6+ //
7+
8+ import Foundation
9+
10+ public protocol TextAttachmentManagerDelegate : AnyObject {
11+ func textAttachmentDidAdd( _ attachment: any TextAttachment , for range: NSRange )
12+ func textAttachmentDidRemove( _ attachment: any TextAttachment , for range: NSRange )
13+ }
Original file line number Diff line number Diff line change @@ -92,9 +92,9 @@ public final class LineFragmentRenderer {
9292 in: context,
9393 rect: NSRect (
9494 x: currentPosition,
95- y: yPos,
95+ y: yPos + ( lineFragment . heightDifference / 2 ) ,
9696 width: attachment. width,
97- height: lineFragment. scaledHeight
97+ height: lineFragment. height
9898 )
9999 )
100100 }
You can’t perform that action at this time.
0 commit comments