         return true
     }
 
+    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
+        let locationInTextView = gestureRecognizer.location(in: richTextView)
+        // check if we have an attachment in the position we tapped
+        guard richTextView.attachmentAtPoint(locationInTextView) != nil else {
+            // if we have a current selected attachment marked lets unmark it
+            if let selectedAttachment = currentSelectedAttachment {
+                selectedAttachment.clearAllOverlays()
+                richTextView.refreshLayoutFor(attachment: selectedAttachment)
+                currentSelectedAttachment = nil
+            }
+            return false
+        }
+        return true
+    }
+
     func richTextViewWasPressed(_ recognizer: UIGestureRecognizer) {
         let locationInTextView = recognizer.location(in: richTextView)
         // check if we have an attachment in the position we tapped
         guard let attachment = richTextView.attachmentAtPoint(locationInTextView) else {
             // if we have an attachment marked lets unmark it
             if let selectedAttachment = currentSelectedAttachment {
-                selectedAttachment.message = nil
                 selectedAttachment.clearAllOverlays()
                 richTextView.refreshLayoutFor(attachment: selectedAttachment)
                 currentSelectedAttachment = nil

        } else {
            // if it's a new attachment tapped let unmark the previous one
            if let selectedAttachment = currentSelectedAttachment {
                selectedAttachment.message = nil
                richTextView.refreshLayoutFor(attachment: selectedAttachment)
            }
            // and mark the newly tapped attachment


    fileprivate(set) lazy var tapGestureRecognizer: UIGestureRecognizer = {
        let recognizer = UITapGestureRecognizer(target: self, action: #selector(richTextViewWasPressed))
        recognizer.cancelsTouchesInView = true
        recognizer.delaysTouchesBegan = true
        recognizer.delaysTouchesEnded = true
        recognizer.delegate = self
        return recognizer
    }()
