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

Commit

Permalink
Fixes #1617: didPressSearch crash (#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz authored Jan 3, 2019
1 parent c69ee1d commit 23df12b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Blockzilla/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ extension BrowserViewController: URLBarDelegate {

if userInputText == trimmedText {
let suggestions = suggestions ?? [trimmedText]
self.overlayView.setSearchQuery(suggestions: suggestions, hideFindInPage: isOnHomeView || text.isEmpty, hideAddToComplete: true)
DispatchQueue.main.async {
self.overlayView.setSearchQuery(suggestions: suggestions, hideFindInPage: isOnHomeView || text.isEmpty, hideAddToComplete: true)
}
}
})
}
Expand Down
7 changes: 4 additions & 3 deletions Blockzilla/OverlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ class OverlayView: UIView {
- Returns: An NSAttributedString with `phrase` localized and styled appropriately.

*/
func getAttributedButtonTitle(phrase: String,
localizedStringFormat: String) -> NSAttributedString {
func getAttributedButtonTitle(phrase: String, localizedStringFormat: String) -> NSAttributedString {
let attributedString = NSMutableAttributedString(string: localizedStringFormat, attributes: [.foregroundColor: UIConstants.Photon.Grey10])
let phraseString = NSAttributedString(string: phrase, attributes: [.font: UIConstants.fonts.copyButtonQuery,
.foregroundColor: UIConstants.Photon.Grey10])
Expand Down Expand Up @@ -304,7 +303,9 @@ class OverlayView: UIView {
}

@objc private func didPressSearch(sender: IndexedInsetButton) {
delegate?.overlayView(self, didSearchForQuery: searchSuggestions[sender.getIndex()])
// Safeguard against a potential update of searchSuggestions causing this index to no longer exist
let immutableSearchSuggestions = searchSuggestions
delegate?.overlayView(self, didSearchForQuery: immutableSearchSuggestions[sender.getIndex()])

if !Settings.getToggle(.enableSearchSuggestions) { return }
if sender.getIndex() == 0 {
Expand Down

0 comments on commit 23df12b

Please sign in to comment.