Skip to content

Commit

Permalink
Fixed an issue where it was possible to set focus in middle of textbl…
Browse files Browse the repository at this point in the history
…ock by setting textblock range
  • Loading branch information
rajdeep committed Jun 27, 2024
1 parent 293aec2 commit a6ca98a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Proton/Sources/Swift/Core/RichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ class RichTextView: AutogrowingTextView {
}
}

override var selectedRange: NSRange {
didSet{
if let range = adjustedTextBlockRangeOnSelectionChange(oldRange: oldValue, newRange: selectedRange) {
selectedRange = range
}
richTextViewDelegate?.richTextView(self, selectedRangeChangedFrom: oldValue, to: selectedRange)
}
}

override var contentInset: UIEdgeInsets {
didSet {
updatePlaceholderVisibility()
Expand Down
13 changes: 13 additions & 0 deletions Proton/Tests/Core/TextBlockAttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ class TextBlockAttributeTests: XCTestCase {
XCTAssertEqual(textView.selectedRange, NSRange(location: 8, length: 0))
}

func testSetsFocusAfterForNonFocusableTextWithSelectedRange() {
let textView = RichTextView(context: RichTextViewContext())
let text = NSMutableAttributedString(string: "0123")
text.append(NSAttributedString(string: "4567", attributes: [.textBlock: true]))
text.append(NSAttributedString(string: "890"))
textView.attributedText = text

textView.selectedRange = .zero
let range = NSRange(location: 5, length: 0)
textView.selectedRange = range
XCTAssertEqual(textView.selectedRange, NSRange(location: 8, length: 0))
}

func testDoubleTapOnTextBlock() {
let textView = RichTextView(context: RichTextViewContext())
let text = NSMutableAttributedString(string: "01234", attributes: [.textBlock: true])
Expand Down

0 comments on commit a6ca98a

Please sign in to comment.