Skip to content

Commit

Permalink
Allow attachment tap to select only when container is editable (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep authored Feb 21, 2024
1 parent cff8373 commit 3ad1684
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Proton/Sources/Swift/Attachment/AttachmentContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
33 changes: 33 additions & 0 deletions Proton/Tests/Editor/EditorSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3ad1684

Please sign in to comment.