diff --git a/Proton/Sources/Swift/Core/RichTextView.swift b/Proton/Sources/Swift/Core/RichTextView.swift index d2f237c2..c624a0ed 100644 --- a/Proton/Sources/Swift/Core/RichTextView.swift +++ b/Proton/Sources/Swift/Core/RichTextView.swift @@ -78,6 +78,18 @@ class RichTextView: AutogrowingTextView { } } + override var contentInset: UIEdgeInsets { + didSet { + updatePlaceholderVisibility() + } + } + + override var textContainerInset: UIEdgeInsets { + didSet { + updatePlaceholderVisibility() + } + } + private func adjustedTextBlockRangeOnSelectionChange(oldRange: NSRange?, newRange: NSRange?) -> NSRange? { guard let old = oldRange, let new = newRange, diff --git a/Proton/Tests/Editor/EditorSnapshotTests.swift b/Proton/Tests/Editor/EditorSnapshotTests.swift index 334a28b8..cfe1d2f6 100644 --- a/Proton/Tests/Editor/EditorSnapshotTests.swift +++ b/Proton/Tests/Editor/EditorSnapshotTests.swift @@ -41,6 +41,22 @@ class EditorSnapshotTests: SnapshotTestCase { assertSnapshot(matching: viewController.view, as: .image, record: recordMode) } + func testUpdatesPlaceholderWithInsets() { + let viewController = EditorTestViewController() + let editor = viewController.editor + editor.contentInset = .zero + editor.textContainerInset = .zero + let font = UIFont(name: "Verdana", size: 17) ?? UIFont() + let placeholderString = NSMutableAttributedString(string: "Placeholder text", attributes: [ + NSAttributedString.Key.font: font, + NSAttributedString.Key.foregroundColor: UIColor.lightGray + ]) + + editor.placeholderText = placeholderString + viewController.render(size: CGSize(width: 300, height: 60)) + assertSnapshot(matching: viewController.view, as: .image, record: recordMode) + } + func testRendersMatchContentAttachment() { let viewController = EditorTestViewController() let editor = viewController.editor diff --git a/Proton/Tests/Editor/__Snapshots__/EditorSnapshotTests/testUpdatesPlaceholderWithInsets.1.png b/Proton/Tests/Editor/__Snapshots__/EditorSnapshotTests/testUpdatesPlaceholderWithInsets.1.png new file mode 100644 index 00000000..911db3f7 Binary files /dev/null and b/Proton/Tests/Editor/__Snapshots__/EditorSnapshotTests/testUpdatesPlaceholderWithInsets.1.png differ