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

Commit

Permalink
Fix #3444: Dont reset the cursor if we arent removing an autofill (#3615
Browse files Browse the repository at this point in the history
)

This is a prior fix from Firefox:
mozilla-mobile/firefox-ios@adfe64a
  • Loading branch information
kylehickinson authored May 3, 2021
1 parent 7560c1f commit 3c4e2d4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Client/Frontend/Widgets/AutocompleteTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,21 @@ class AutocompleteTextField: UITextField, UITextFieldDelegate {

// Clear the current completion, then set the text without the attributed style.
let text = (self.text ?? "") + (self.autocompleteTextLabel?.text ?? "")
removeCompletion()
let didRemoveCompletion = removeCompletion()
self.text = text
hideCursor = false
// Move the cursor to the end of the completion.
selectedTextRange = textRange(from: endOfDocument, to: endOfDocument)
if didRemoveCompletion {
selectedTextRange = textRange(from: endOfDocument, to: endOfDocument)
}
}

/// Removes the autocomplete-highlighted
fileprivate func removeCompletion() {
/// Removes the autocomplete-highlighted. Returns true if a completion was actually removed
@objc @discardableResult fileprivate func removeCompletion() -> Bool {
let hasActiveCompletion = isSelectionActive
autocompleteTextLabel?.removeFromSuperview()
autocompleteTextLabel = nil
return hasActiveCompletion
}

// `shouldChangeCharactersInRange` is called before the text changes, and textDidChange is called after.
Expand Down

0 comments on commit 3c4e2d4

Please sign in to comment.