Skip to content

Commit

Permalink
Fixed attachment recursive crash (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep authored Nov 15, 2023
1 parent 7d72127 commit f188a89
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Proton/Sources/Swift/Attachment/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ open class Attachment: NSTextAttachment, BoundsObserving {
/// `BoundsObserving`
public func didChangeBounds(_ bounds: CGRect, oldBounds: CGRect) {
// check how view.bounds can be checked against attachment.bounds
guard oldBounds != .zero else { return }
// Check for zero bounds required so that rendering attachment does not go recursive in `relayoutAttachments`
guard bounds != .zero, oldBounds != .zero else { return }
invalidateLayout()
}

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

if containerTextView?.isScrollEnabled == false, needsInvalidation {
Expand Down
1 change: 0 additions & 1 deletion Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,6 @@ extension EditorView {
self.delegate?.editor(self, didRenderAttachment: attachment)
}
}

attachment.frame = frame
}
attachmentRenderingScheduler.executeNext()
Expand Down

0 comments on commit f188a89

Please sign in to comment.