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

Commit

Permalink
Fix #8332: Allow proper caret selection on url bar in overlay mode
Browse files Browse the repository at this point in the history
This cleans up the duplicate drag interactions as well as fixes the bug where you could no longer move the caret inside of the url bar text field. It also restores a missed delegate method and removes the drop delegate on the active text field so as to not crash
  • Loading branch information
kylehickinson committed Oct 31, 2023
1 parent fe0d7e9 commit 83da27b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@ class TabLocationView: UIView {
contentView.snp.makeConstraints { make in
make.leading.trailing.top.bottom.equalTo(self)
}

// Setup UIDragInteraction to handle dragging the location
// bar for dropping its URL into other apps.
let dragInteraction = UIDragInteraction(delegate: self)
dragInteraction.allowsSimultaneousRecognitionDuringLift = true
self.addInteraction(dragInteraction)

privateModeCancellable = privateBrowsingManager.$isPrivateBrowsing
.removeDuplicates()
Expand Down Expand Up @@ -414,26 +408,6 @@ class TabLocationView: UIView {
}
}

// MARK: - UIDragInteractionDelegate

extension TabLocationView: UIDragInteractionDelegate {
func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] {
// Ensure we actually have a URL in the location bar and that the URL is not local.
guard let url = self.url, !InternalURL.isValid(url: url), let itemProvider = NSItemProvider(contentsOf: url),
!reloadButton.isHighlighted
else {
return []
}

let dragItem = UIDragItem(itemProvider: itemProvider)
return [dragItem]
}

func dragInteraction(_ interaction: UIDragInteraction, sessionWillBegin session: UIDragSession) {
delegate?.tabLocationViewDidBeginDragInteraction(self)
}
}

// MARK: - TabEventHandler

extension TabLocationView: TabEventHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ class TopToolbarView: UIView, ToolbarProtocol {
swipeGestureRecognizer.isEnabled = false
locationView.addGestureRecognizer(swipeGestureRecognizer)

let dragInteraction = UIDragInteraction(delegate: self)
dragInteraction.allowsSimultaneousRecognitionDuringLift = true
locationView.addInteraction(dragInteraction)

self.displayTabTraySwipeGestureRecognizer = swipeGestureRecognizer

qrCodeButton.addTarget(self, action: #selector(topToolbarDidPressQrCodeButton), for: .touchUpInside)
Expand Down Expand Up @@ -412,11 +416,11 @@ class TopToolbarView: UIView, ToolbarProtocol {
$0.attributedPlaceholder = self.locationView.makePlaceholder(colors: .standard)
$0.clearButtonMode = .whileEditing
$0.rightViewMode = .never
if let dropInteraction = $0.textDropInteraction {
$0.removeInteraction(dropInteraction)
}
}

let dragInteraction = UIDragInteraction(delegate: self)
locationTextField.addInteraction(dragInteraction)

if RecentSearchQRCodeScannerController.hasCameraSupport {
locationBarOptionsStackView.addArrangedSubview(qrCodeButton)
}
Expand Down Expand Up @@ -807,12 +811,19 @@ extension TopToolbarView: AutocompleteTextFieldDelegate {

extension TopToolbarView: UIDragInteractionDelegate {
func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] {
guard let text = locationTextField?.text else {
// Ensure we actually have a URL in the location bar and that the URL is not local.
guard let url = self.locationView.url, !InternalURL.isValid(url: url), let itemProvider = NSItemProvider(contentsOf: url),
!locationView.reloadButton.isHighlighted, !inOverlayMode
else {
return []
}
let dragItem = UIDragItem(itemProvider: NSItemProvider(object: text as NSString))

let dragItem = UIDragItem(itemProvider: itemProvider)
dragItem.localObject = locationTextField
return [dragItem]
}

func dragInteraction(_ interaction: UIDragInteraction, sessionWillBegin session: UIDragSession) {
delegate?.topToolbarDidBeginDragInteraction(self)
}
}

0 comments on commit 83da27b

Please sign in to comment.