Skip to content

Commit

Permalink
Added EditorViewDelegate callback for willRenderAttachment
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Apr 16, 2024
1 parent fb644a8 commit 3f8f365
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ extension EditorView {
}
}
} else {
self.delegate?.editor(self, willRenderAttachment: attachment)
attachment.render(in: self)
if !self.isSettingAttributedText, let focusable = attachment.contentView as? Focusable {
focusable.setFocus()
Expand Down
10 changes: 10 additions & 0 deletions Proton/Sources/Swift/Editor/EditorViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ public protocol EditorViewDelegate: AnyObject {
/// - isEditable: `true` if editor is editable, else `false`
func editor(_ editor: EditorView, didChangeEditable isEditable: Bool)

/// Notifies when an `Attachment` is going to rendered for the first time in `EditorView`
/// - Parameters:
/// - editor: Editor view receiving the event.
/// - attachment: `Attachment` getting rendered
/// - Note:
/// This invocation only applies in default mode of rendering attachment. If `EditorView` has `AsyncAttachmentRenderingDelegate` provided,
/// that delegate will receive the event instead.
func editor(_ editor: EditorView, willRenderAttachment attachment: Attachment)

/// Notifies when an `Attachment` is rendered for the first time in `EditorView`
/// - Parameters:
/// - editor: Editor view receiving the event.
Expand Down Expand Up @@ -153,6 +162,7 @@ public extension EditorViewDelegate {
func editor(_ editor: EditorView, didSetAttributedText attributedText: NSAttributedString, isDeferred: Bool) { }
func editor(_ editor: EditorView, isReady: Bool) { }
func editor(_ editor: EditorView, didChangeEditable isEditable: Bool) { }
func editor(_ editor: EditorView, willRenderAttachment attachment: Attachment) { }
func editor(_ editor: EditorView, didRenderAttachment attachment: Attachment) { }
func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool? {
return nil
Expand Down

0 comments on commit 3f8f365

Please sign in to comment.