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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public final class TextAttachmentManager {
weak var layoutManager: TextLayoutManager?
private var selectionObserver: (any NSObjectProtocol)?

public weak var delegate: TextAttachmentManagerDelegate?

/// Adds a new attachment, keeping `orderedAttachments` sorted by range.location.
/// If two attachments overlap, the layout phase will later ignore the one with the higher start.
/// - Complexity: `O(n log(n))` due to array insertion. Could be improved with a binary tree.
Expand Down Expand Up @@ -47,6 +49,8 @@ public final class TextAttachmentManager {
}

layoutManager?.setNeedsLayout()

delegate?.textAttachmentDidAdd(attachment.attachment, for: range)
}

/// Removes an attachment and invalidates layout for the removed range.
Expand All @@ -62,6 +66,9 @@ public final class TextAttachmentManager {

let attachment = orderedAttachments.remove(at: index)
layoutManager?.invalidateLayoutForRange(attachment.range)

delegate?.textAttachmentDidRemove(attachment.attachment, for: attachment.range)

return attachment
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TextAttachmentManagerDelegate.swift
// CodeEditTextView
//
// Created by Khan Winter on 6/25/25.
//

import Foundation

public protocol TextAttachmentManagerDelegate: AnyObject {
func textAttachmentDidAdd(_ attachment: any TextAttachment, for range: NSRange)
func textAttachmentDidRemove(_ attachment: any TextAttachment, for range: NSRange)
}
4 changes: 2 additions & 2 deletions Sources/CodeEditTextView/TextLine/LineFragmentRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public final class LineFragmentRenderer {
in: context,
rect: NSRect(
x: currentPosition,
y: yPos,
y: yPos + (lineFragment.heightDifference/2),
width: attachment.width,
height: lineFragment.scaledHeight
height: lineFragment.height
)
)
}
Expand Down