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

Commit

Permalink
Selection with text range instead of select all
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Jan 3, 2024
1 parent 1c6d636 commit 2ef0068
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 2ef0068

Please sign in to comment.