Skip to content

Commit

Permalink
Fix brave/brave-ios#8374: Cursor is misplaced for a selected URL when…
Browse files Browse the repository at this point in the history
… that URL doesn't fit the screen (brave/brave-ios#8612)
  • Loading branch information
soner-yuksel authored Jan 4, 2024
1 parent a1f274f commit 57c0c28
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -621,20 +621,27 @@ class TopToolbarView: UIView, ToolbarProtocol {
// look squished at the start of the animation and expand to be correct. As a workaround,
// we becomeFirstResponder as the next event on UI thread, so the animation starts before we
// set a first responder.
guard let urlTextField = locationTextField else {
return
}

if pasted {
// Clear any existing text, focus the field, then set the actual pasted text.
// This avoids highlighting all of the text.
locationTextField?.text = ""
DispatchQueue.main.async {
self.locationTextField?.becomeFirstResponder()
self.setLocation(locationText, search: search)
}
} else {
urlTextField.text = ""
}

DispatchQueue.main.async {
urlTextField.becomeFirstResponder()
self.setLocation(locationText, search: search)
}

if !pasted {
DispatchQueue.main.async {
self.locationTextField?.becomeFirstResponder()
// Need to set location again so text could be immediately selected.
self.setLocation(locationText, search: search)
self.locationTextField?.selectAll(nil)
// When Not-pasted selecting text shiuld be from beggining to end
let textRange = urlTextField.textRange(
from: urlTextField.beginningOfDocument, to: urlTextField.endOfDocument)
urlTextField.selectedTextRange = textRange
}
}

Expand Down

0 comments on commit 57c0c28

Please sign in to comment.