         return textView
     }()
 
-    fileprivate(set) lazy var htmlTextView: UITextView = {
+    fileprivate(set) lazy var htmlTextView: UITextView = { [weak self] in
         let defaultFont: UIFont
 
         if #available(iOS 11, *) {

    fileprivate func refreshInsets(forKeyboardFrame keyboardFrame: CGRect) {
        let referenceView: UIScrollView = editingMode == .richText ? richTextView : htmlTextView

        let scrollInsets = UIEdgeInsets(top: referenceView.scrollIndicatorInsets.top, left: 0, bottom: view.frame.maxY - (keyboardFrame.minY + self.view.layoutMargins.bottom), right: 0)
        let contentInset = UIEdgeInsets(top: referenceView.contentInset.top, left: 0, bottom: view.frame.maxY - (keyboardFrame.minY + self.view.layoutMargins.bottom), right: 0)

        htmlTextView.scrollIndicatorInsets = scrollInsets
        htmlTextView.contentInset = contentInset

        let alertController = UIAlertController(title: title, message:message, preferredStyle: .actionSheet)
        let dismissAction = UIAlertAction(title: NSLocalizedString("Dismiss", comment: "User action to dismiss media options."),
                                          style: .cancel,
                                          handler: { [weak self] (action) in
                                            self?.resetMediaAttachmentOverlay(attachment)
                                            self?.richTextView.refresh(attachment)
        }
        )
        alertController.addAction(dismissAction)

        let removeAction = UIAlertAction(title: NSLocalizedString("Remove Media", comment: "User action to remove media."),
                                         style: .destructive,
                                         handler: { [weak self] (action) in
                                            self?.richTextView.remove(attachmentID: mediaID)
        })
        alertController.addAction(removeAction)

        if let imageAttachment = attachment as? ImageAttachment {
            let detailsAction = UIAlertAction(title:NSLocalizedString("Media Details", comment: "User action to change media details."),
                                              style: .default,
                                              handler: { [weak self] (action) in
                                                self?.displayDetailsForAttachment(imageAttachment, position: position)
            })
            alertController.addAction(detailsAction)
        } else if let videoAttachment = attachment as? VideoAttachment, let videoURL = videoAttachment.srcURL {
            let detailsAction = UIAlertAction(title:NSLocalizedString("Play Video", comment: "User action to play video."),
                                              style: .default,
                                              handler: { [weak self] (action) in
                                                self?.displayVideoPlayer(for: videoURL)
            })
            alertController.addAction(detailsAction)
        }
