Skip to content

Commit

Permalink
Clamped range for invalidating layout of RichTextView
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Mar 13, 2024
1 parent 2c4fccd commit 788ebca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Proton/Sources/Swift/Core/RichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,11 @@ class RichTextView: AutogrowingTextView {
}

func invalidateLayout(for range: NSRange) {
layoutManager.invalidateLayout(forCharacterRange: range, actualCharacterRange: nil)
layoutManager.invalidateLayout(forCharacterRange: range.clamped(upperBound: textStorage.length), actualCharacterRange: nil)
}

func invalidateDisplay(for range: NSRange) {
// invalidateDisplay does not need clamping like required by invalidateLayout
layoutManager.invalidateDisplay(forCharacterRange: range)
}

Expand Down
14 changes: 14 additions & 0 deletions Proton/Tests/Core/RichTextViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ class RichTextViewTests: XCTestCase {
XCTAssertEqual(textView.attributedText.string, "")
}

func testUsesValidRangeForInvalidatingLayout() {
let text = NSAttributedString(string: "test")
let textView = RichTextView(context: RichTextViewContext())
textView.attributedText = text
textView.invalidateLayout(for: NSRange(location: 20, length: 4))
}

func testUsesValidRangeForInvalidatingDisplay() {
let text = NSAttributedString(string: "test")
let textView = RichTextView(context: RichTextViewContext())
textView.attributedText = text
textView.invalidateDisplay(for: NSRange(location: 20, length: 4))
}

private func assertKeyCommand(input: String, modifierFlags: UIKeyModifierFlags, assertions: @escaping ((EditorKey, UIKeyModifierFlags) -> Void), file: StaticString = #file, line: UInt = #line) {
let funcExpectation = functionExpectation()
let textView = RichTextView(context: RichTextViewContext())
Expand Down

0 comments on commit 788ebca

Please sign in to comment.