Skip to content

Commit

Permalink
(#168) Fixed editor placeholder on change of insets (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep authored Apr 14, 2023
1 parent 156f753 commit ed92d74
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Proton/Sources/Swift/Core/RichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions Proton/Tests/Editor/EditorSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 ed92d74

Please sign in to comment.