Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8374: Cursor is misplaced for a selected URL when that URL doesn't fit the screen #8612

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
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