Skip to content

Commit

Permalink
Fixed logic to not nil out selectedEditorView
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Aug 22, 2024
1 parent dc80a7c commit 62bd43f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Proton/Sources/Swift/Core/RichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ class RichTextView: AutogrowingTextView {
}

func didTap(at location: CGPoint) {
context?.selectedTextView = self
if isEditable == false {
context?.selectedTextView = self
}
let characterRange = rangeOfCharacter(at: location)
richTextViewDelegate?.richTextView(self, didTapAtLocation: location, characterRange: characterRange)
}
Expand Down
9 changes: 2 additions & 7 deletions Proton/Sources/Swift/Core/RichTextViewContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ class RichTextViewContext: NSObject, UITextViewDelegate {

func textViewDidChangeSelection(_ textView: UITextView) {
guard textView.delegate === self else { return }
if textView.selectedTextRange != nil {
if (textView.isEditable && textView.isFirstResponder) ||
textView.isEditable == false {
if (textView.isEditable && textView.isFirstResponder) || textView.isEditable == false {
if textView.selectedTextRange != nil {
selectedTextView = textView.asRichTextView
} else {
selectedTextView = nil
}
} else {
selectedTextView = nil
}

guard let richTextView = textView as? RichTextView else { return }
Expand Down
4 changes: 2 additions & 2 deletions Proton/Tests/Core/RichTextViewContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,14 @@ class RichTextViewContextTests: XCTestCase {
waitForExpectations(timeout: 1.0)
}

func testSetsSelectedEditorOnTap() {
func testSetsSelectedReadOnlyEditorOnTap() {
let testExpectation = expectation(description: #function)
let mockTextViewDelegate = MockRichTextViewDelegate()

let context = RichTextEditorContext.default
let textView = RichTextView(context: context)
textView.richTextViewDelegate = mockTextViewDelegate

textView.isEditable = false
textView.text = "Sample text"
textView.selectedTextRange = nil

Expand Down

0 comments on commit 62bd43f

Please sign in to comment.