         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: { (action) in
-                                            self.resetMediaAttachmentOverlay(attachment)
-                                            self.richTextView.refresh(attachment)
+                                          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: { (action) in
-                                            self.richTextView.remove(attachmentID: mediaID)
+                                         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: { (action) in
-                                                self.displayDetailsForAttachment(imageAttachment, position: position)
+                                              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: { (action) in
-                                                self.displayVideoPlayer(for: videoURL)
+                                              handler: { [weak self] (action) in
+                                                self?.displayVideoPlayer(for: videoURL)
             })
             alertController.addAction(detailsAction)
         }

            insertAction.isEnabled = !text.isEmpty
        }

        self.present(alertController, animated:true, completion:nil)
    }

    @objc func alertTextFieldDidChange(_ textField: UITextField) {

    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 + view.layoutMargins.bottom), right: 0)
        let contentInset = UIEdgeInsets(top: referenceView.contentInset.top, left: 0, bottom: view.frame.maxY - (keyboardFrame.minY + view.layoutMargins.bottom), right: 0)

        htmlTextView.scrollIndicatorInsets = scrollInsets
        htmlTextView.contentInset = contentInset
