Skip to content

Commit f188a89

Browse files
authored
Fixed attachment recursive crash (#252)
1 parent 7d72127 commit f188a89

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: Proton/Sources/Swift/Attachment/Attachment.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ open class Attachment: NSTextAttachment, BoundsObserving {
363363
/// `BoundsObserving`
364364
public func didChangeBounds(_ bounds: CGRect, oldBounds: CGRect) {
365365
// check how view.bounds can be checked against attachment.bounds
366-
guard oldBounds != .zero else { return }
366+
// Check for zero bounds required so that rendering attachment does not go recursive in `relayoutAttachments`
367+
guard bounds != .zero, oldBounds != .zero else { return }
367368
invalidateLayout()
368369
}
369370

@@ -586,7 +587,9 @@ extension Attachment {
586587
let range = rangeInContainer()
587588
else { return }
588589
cachedBounds = nil
589-
let needsInvalidation = bounds.integral.size != contentView?.bounds.integral.size
590+
// Check for zero bounds required so that rendering attachment does not go recursive in `relayoutAttachments`
591+
let needsInvalidation = bounds.integral.size != .zero
592+
&& bounds.integral.size != contentView?.bounds.integral.size
590593
editor.invalidateLayout(for: range)
591594

592595
if containerTextView?.isScrollEnabled == false, needsInvalidation {

Diff for: Proton/Sources/Swift/Editor/EditorView.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,6 @@ extension EditorView {
14021402
self.delegate?.editor(self, didRenderAttachment: attachment)
14031403
}
14041404
}
1405-
14061405
attachment.frame = frame
14071406
}
14081407
attachmentRenderingScheduler.executeNext()

0 commit comments

Comments
 (0)