wordpress-mobile / AztecEditor-iOS

A reusable native iOS visual HTML text editor component.
Mozilla Public License 2.0
615 stars 147 forks source link

TextView crashes app because textAttachmentDelegate? not set. #1397

Open srosenbaumCB opened 4 months ago

srosenbaumCB commented 4 months ago

Describe the bug

TextView func storage(_ storage: TextStorage, placeholderFor attachment: NSTextAttachment) -> UIImage is crashing my app in production of the following guard statement contains a fatalError.

        guard let textAttachmentDelegate = textAttachmentDelegate else {
            fatalError("This class requires a text attachment delegate to be set.")
        }

        return textAttachmentDelegate.textView(self, placeholderFor: attachment)

The problem with this is that earlier in the file the following is explicitly stated for the textAttachmentDelegate optional.

    /// The media delegate takes care of providing remote media when requested by the `TextView`.
    /// If this is not set, all remove images will be left blank.
    ///
    open weak var textAttachmentDelegate: TextViewAttachmentDelegate?

Which would imply that the TextView will continue to function, only without displaying images. Not fatalError crashing.

This seems to be the case with all of the storage functions.

To Reproduce Steps to reproduce the behavior:

Create an instance of the TextView without instantiating textAttachmentDelegate

  1. Render the Field in a SwiftUI view.

Expected behavior A clear and concise description of what you expected to happen.

A TextView should continue to run rendering the HTML and images remain blank, WITHOUT crashing the app, as implied by the documentation. (Unless there is actually something called 'remove images'.)

Screenshots If applicable, add screenshots to help explain your problem. simulator_screenshot_BCB48876-BD8C-45A0-AE68-F9D31201CD38

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.