Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with double tapping on textblock that may cause selected … #300

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Proton/Sources/Swift/Core/RichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ class RichTextView: AutogrowingTextView {
textBlockRange.contains(location)
else { return nil }

// return textblock range if new range is entirely contained within textblock range
if textBlockRange.intersection(new) == new {
return textBlockRange
}

if isReverseTraversal {
return adjustedTextBlockRangeReverse(new: new, old: old, textBlockRange: textBlockRange)
} else {
Expand Down
19 changes: 15 additions & 4 deletions Proton/Tests/Core/TextBlockAttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class TextBlockAttributeTests: XCTestCase {
XCTAssertEqual(textView.selectedRange, NSRange(location: 8, length: 0))
}

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

textView.selectedRange = text.fullRange
let range = NSRange(location: 0, length: 1).toTextRange(textInput: textView)
textView.selectedTextRange = range
XCTAssertEqual(textView.selectedRange, text.fullRange)
}

func testSetsFocusBeforeForNonFocusableText() {
let textView = RichTextView(context: RichTextViewContext())
let text = NSMutableAttributedString(string: "0123")
Expand Down Expand Up @@ -147,7 +158,7 @@ class TextBlockAttributeTests: XCTestCase {
XCTAssertEqual(range, NSRange(location: 12, length: 7))
}

func testUnselectsSelectedTextBlockForward() {
func testRetainsSelectedTextBlockForward() {
let textView = RichTextView(context: RichTextViewContext())
let text = NSMutableAttributedString(string: "This is test string")
textView.attributedText = text
Expand All @@ -157,10 +168,10 @@ class TextBlockAttributeTests: XCTestCase {
textView.selectedTextRange = NSRange(location: 9, length: 3).toTextRange(textInput: textView) // "est"
let range = textView.selectedRange

XCTAssertEqual(range, NSRange(location: 12, length: 0))
XCTAssertEqual(range, NSRange(location: 8, length: 4))
}

func testUnselectsSelectedTextBlockReverse() {
func testRetainsSelectedTextBlockReverse() {
let textView = RichTextView(context: RichTextViewContext())
let text = NSMutableAttributedString(string: "This is test string")
textView.attributedText = text
Expand All @@ -170,7 +181,7 @@ class TextBlockAttributeTests: XCTestCase {
textView.selectedTextRange = NSRange(location: 8, length: 3).toTextRange(textInput: textView) // "tes"
let range = textView.selectedRange

XCTAssertEqual(range, NSRange(location: 8, length: 0))
XCTAssertEqual(range, NSRange(location: 8, length: 4))
}

func testUnselectsTextSelectedWithTextBlockReverse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class NSAttributedStringExtensionTests: XCTestCase {
XCTAssertEqual(range, NSRange(location: 0, length: text.length))
}

func testGetsSubstring() {
let text = NSAttributedString(string: "This is a test string")
let substring = text.substring(from: NSRange(location: 5, length: 2))
XCTAssertEqual(substring, "is")
}

func testGetRangeForAttachment() {
let string = "This is a test string"
let text = NSMutableAttributedString(string: string)
Expand Down
Loading