From f188a8985b3a072e3513c1d351524b26cf71e538 Mon Sep 17 00:00:00 2001 From: Rajdeep Kwatra Date: Thu, 16 Nov 2023 09:03:48 +1100 Subject: [PATCH] Fixed attachment recursive crash (#252) --- Proton/Sources/Swift/Attachment/Attachment.swift | 7 +++++-- Proton/Sources/Swift/Editor/EditorView.swift | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Proton/Sources/Swift/Attachment/Attachment.swift b/Proton/Sources/Swift/Attachment/Attachment.swift index 839e2fd4..f4d1ce32 100644 --- a/Proton/Sources/Swift/Attachment/Attachment.swift +++ b/Proton/Sources/Swift/Attachment/Attachment.swift @@ -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() } @@ -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 { diff --git a/Proton/Sources/Swift/Editor/EditorView.swift b/Proton/Sources/Swift/Editor/EditorView.swift index 463b81c2..fe72da46 100644 --- a/Proton/Sources/Swift/Editor/EditorView.swift +++ b/Proton/Sources/Swift/Editor/EditorView.swift @@ -1402,7 +1402,6 @@ extension EditorView { self.delegate?.editor(self, didRenderAttachment: attachment) } } - attachment.frame = frame } attachmentRenderingScheduler.executeNext()