diff --git a/Proton/Sources/Swift/Attachment/AttachmentContent.swift b/Proton/Sources/Swift/Attachment/AttachmentContent.swift index f8db3079..9babb249 100644 --- a/Proton/Sources/Swift/Attachment/AttachmentContent.swift +++ b/Proton/Sources/Swift/Attachment/AttachmentContent.swift @@ -55,7 +55,8 @@ class AttachmentContentView: UIView { } func onContentViewTapped() { - guard attachment?.selectOnTap == true else { return } + guard attachment?.containerEditorView?.isEditable == true, + attachment?.selectOnTap == true else { return } attachment?.setSelected(true) } } diff --git a/Proton/Tests/Editor/EditorSnapshotTests.swift b/Proton/Tests/Editor/EditorSnapshotTests.swift index 9df76b2f..478a094d 100644 --- a/Proton/Tests/Editor/EditorSnapshotTests.swift +++ b/Proton/Tests/Editor/EditorSnapshotTests.swift @@ -1413,6 +1413,39 @@ class EditorSnapshotTests: SnapshotTestCase { assertSnapshot(matching: viewController.view, as: .image, record: recordMode) } + func testSelectOnTapInNonEditableEditor() { + let viewController = EditorTestViewController() + let editor = viewController.editor + let offsetProvider = MockAttachmentOffsetProvider() + offsetProvider.offset = CGPoint(x: 0, y: -4) + + editor.font = UIFont.systemFont(ofSize: 12) + + var panel = PanelView() + panel.editor.forceApplyAttributedText = true + panel.backgroundColor = .cyan + panel.layer.borderWidth = 1.0 + panel.layer.cornerRadius = 4.0 + panel.layer.borderColor = UIColor.black.cgColor + + let attachment = Attachment(panel, size: .fullWidth) + panel.boundsObserver = attachment + panel.editor.font = editor.font + + panel.attributedText = NSAttributedString(string: "In full-width attachment") + + editor.replaceCharacters(in: .zero, with: "This text is in Editor") + editor.insertAttachment(in: editor.textEndRange, attachment: attachment) + + editor.isEditable = false + let touch = UITouch() + attachment.selectOnTap = true + (attachment.contentView?.superview as? AttachmentContentView)?.onContentViewTapped() + + viewController.render() + assertSnapshot(matching: viewController.view, as: .image, record: recordMode) + } + private func addCaretRect(at range: NSRange, in editor: EditorView, color: UIColor) { let rect = editor.caretRect(for: range.location) let view = UIView(frame: rect) diff --git a/Proton/Tests/Editor/__Snapshots__/EditorSnapshotTests/testSelectOnTapInNonEditableEditor.1.png b/Proton/Tests/Editor/__Snapshots__/EditorSnapshotTests/testSelectOnTapInNonEditableEditor.1.png new file mode 100644 index 00000000..f5f19176 Binary files /dev/null and b/Proton/Tests/Editor/__Snapshots__/EditorSnapshotTests/testSelectOnTapInNonEditableEditor.1.png differ