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

Commit

Permalink
Fix #2336: Add option to disable Bookmarks/OpenTabs/History suggestio…
Browse files Browse the repository at this point in the history
…ns when typing in url (#8469)
  • Loading branch information
soner-yuksel authored Dec 8, 2023
1 parent 6f6a550 commit 542be8f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Sources/Brave/Frontend/Browser/Search/SearchEngines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ public class SearchEngines {
get { return Preferences.Search.shouldShowRecentSearches.value }
set { Preferences.Search.shouldShowRecentSearches.value = newValue }
}

var shouldShowBrowserSuggestions: Bool {
get { return Preferences.Search.showBrowserSuggestions.value }
set { Preferences.Search.showBrowserSuggestions.value = newValue }
}

func isEngineEnabled(_ engine: OpenSearchEngine) -> Bool {
return disabledEngineNames.index(forKey: engine.shortName) == nil
Expand Down
8 changes: 8 additions & 0 deletions Sources/Brave/Frontend/Browser/Search/SearchLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class SearchLoader: Loader<[Site], SearchViewController> {

var query: String = "" {
didSet {
// Browser suggestions preference control frequencey query over browser items
// like Open Tabs, Bookmarks, History. Disabling this preference should prevent
// data fetch from the sources
guard Preferences.Search.showBrowserSuggestions.value else {
load([])
return
}

if query.isEmpty {
load([])
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ class SearchSuggestionDataSource {
sections.append(.searchSuggestions)
}
sections.append(.findInPage)
sections.append(.openTabsAndHistoryAndBookmarks)

if searchEngines?.shouldShowBrowserSuggestions == true {
sections.append(.openTabsAndHistoryAndBookmarks)
}

return sections
}

Expand Down
12 changes: 12 additions & 0 deletions Sources/Brave/Frontend/Browser/Search/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ public class SearchViewController: SiteTableViewController, LoaderListener {
case .searchSuggestions:
return dataSource.suggestions.isEmpty ? 0 : headerHeight * 2.0
case .openTabsAndHistoryAndBookmarks:
// Check for History Bookmarks Open Tabs suggestions
// Show Browser Suggestions Preference effects all the modes
if !Preferences.Search.showBrowserSuggestions.value {
return 0
}

// Private Browsing Mode (PBM) should *not* show items from normal mode History etc
// when search suggestions is not enabled
if Preferences.Privacy.privateBrowsingOnly.value,
Expand Down Expand Up @@ -667,6 +673,12 @@ public class SearchViewController: SiteTableViewController, LoaderListener {
!dataSource.searchQuery.looksLikeAURL() &&
!dataSource.tabType.isPrivate ? searchSuggestionsCount : 0
case .openTabsAndHistoryAndBookmarks:
// Check for History Bookmarks Open Tabs suggestions
// Show Browser Suggestions Preference effects all the modes
if !Preferences.Search.showBrowserSuggestions.value {
return 0
}

// Private Browsing Mode (PBM) should *not* show items from normal mode History etc
// when search suggestions is not enabled
if Preferences.Privacy.privateBrowsingOnly.value, dataSource.searchEngines?.shouldShowSearchSuggestions == false {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Brave/Frontend/ClientPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ extension Preferences {
static let shouldShowRecentSearches = Option<Bool>(key: "search.should-show-recent-searches", default: false)
/// Whether or not to show recent searches opt-in
static let shouldShowRecentSearchesOptIn = Option<Bool>(key: "search.should-show-recent-searches.opt-in", default: true)
/// Whether or not to show suggestions from browser `Open Tabs & Bookmarks & History` while the user types
static let showBrowserSuggestions = Option<Bool>(key: "search.show-browser-suggestions", default: true)
/// How many times Brave Search websites has asked the user to check whether Brave Search can be set as a default
static let braveSearchDefaultBrowserPromptCount =
Option<Int>(key: "search.brave-search-default-website-prompt", default: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SearchSettingsTableViewController: UITableViewController {
static let searchEngineRowIdentifier = "searchEngineRowIdentifier"
static let showSearchSuggestionsRowIdentifier = "showSearchSuggestionsRowIdentifier"
static let showRecentSearchesRowIdentifier = "showRecentSearchRowIdentifier"
static let showBrowserSuggestionsRowIdentifier = "showBrowserSuggestionsRowIdentifier"
static let quickSearchEngineRowIdentifier = "quickSearchEngineRowIdentifier"
static let customSearchEngineRowIdentifier = "customSearchEngineRowIdentifier"
}
Expand All @@ -52,8 +53,9 @@ class SearchSettingsTableViewController: UITableViewController {
case standard
case `private`
case quick
case suggestions
case searchSuggestions
case recentSearches
case browserSuggestions
}

private var searchEngines: SearchEngines
Expand Down Expand Up @@ -106,6 +108,7 @@ class SearchSettingsTableViewController: UITableViewController {
$0.register(UITableViewCell.self, forCellReuseIdentifier: Constants.searchEngineRowIdentifier)
$0.register(UITableViewCell.self, forCellReuseIdentifier: Constants.showSearchSuggestionsRowIdentifier)
$0.register(UITableViewCell.self, forCellReuseIdentifier: Constants.showRecentSearchesRowIdentifier)
$0.register(UITableViewCell.self, forCellReuseIdentifier: Constants.showBrowserSuggestionsRowIdentifier)
$0.register(UITableViewCell.self, forCellReuseIdentifier: Constants.quickSearchEngineRowIdentifier)
$0.register(UITableViewCell.self, forCellReuseIdentifier: Constants.customSearchEngineRowIdentifier)
$0.sectionHeaderTopPadding = 5
Expand Down Expand Up @@ -211,7 +214,7 @@ class SearchSettingsTableViewController: UITableViewController {
$0.accessoryType = .disclosureIndicator
$0.editingAccessoryType = .disclosureIndicator
}
case CurrentEngineType.suggestions.rawValue:
case CurrentEngineType.searchSuggestions.rawValue:
let toggle = UISwitch().then {
$0.addTarget(self, action: #selector(didToggleSearchSuggestions), for: .valueChanged)
$0.isOn = searchEngines.shouldShowSearchSuggestions
Expand All @@ -233,6 +236,20 @@ class SearchSettingsTableViewController: UITableViewController {
$0.accessoryView = toggle
$0.selectionStyle = .none
}
case CurrentEngineType.browserSuggestions.rawValue:
let toggle = UISwitch().then {
$0.addTarget(self, action: #selector(didToggleBrowserSuggestions), for: .valueChanged)
$0.isOn = searchEngines.shouldShowBrowserSuggestions
}

cell = UITableViewCell(style: .subtitle, reuseIdentifier: Constants.showBrowserSuggestionsRowIdentifier).then {
$0.textLabel?.text = Strings.searchSettingBrowserSuggestionCellTitle
$0.detailTextLabel?.numberOfLines = 0
$0.detailTextLabel?.textColor = .secondaryBraveLabel
$0.detailTextLabel?.text = Strings.searchSettingBrowserSuggestionCellDescription
$0.accessoryView = toggle
$0.selectionStyle = .none
}
default:
// Should not happen.
break
Expand Down Expand Up @@ -367,6 +384,11 @@ extension SearchSettingsTableViewController {
searchEngines.shouldShowRecentSearches = toggle.isOn
searchEngines.shouldShowRecentSearchesOptIn = false
}

@objc func didToggleBrowserSuggestions(_ toggle: UISwitch) {
// Setting the value effects all the modes private normal pbo
searchEngines.shouldShowBrowserSuggestions = toggle.isOn
}

@objc func dismissAnimated() {
self.dismiss(animated: true, completion: nil)
Expand Down
11 changes: 10 additions & 1 deletion Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,20 @@ extension Strings {
value: "Reader Mode", comment: "Title of a bar that show up when you enter reader mode.")
}

// MARK:- SearchSettingsTableViewController.swift
// MARK: - SearchSettingsTableViewController

extension Strings {
public static let searchSettingNavTitle = NSLocalizedString("SearchSettingNavTitle", tableName: "BraveShared", bundle: .module, value: "Search", comment: "Navigation title for search settings.")
public static let searchSettingSuggestionCellTitle = NSLocalizedString("SearchSettingSuggestionCellTitle", tableName: "BraveShared", bundle: .module, value: "Show Search Suggestions", comment: "Label for show search suggestions setting.")
public static let searchSettingRecentSearchesCellTitle = NSLocalizedString("SearchSettingRecentSearchesCellTitle", tableName: "BraveShared", bundle: .module, value: "Show Recent Searches", comment: "Label for showing recent search setting.")
public static let searchSettingBrowserSuggestionCellTitle =
NSLocalizedString("SearchSettingBrowserSuggestionCellTitle", tableName: "BraveShared", bundle: .module,
value: "Show Browser Suggestions",
comment: "Label for showing browser suggestion setting")
public static let searchSettingBrowserSuggestionCellDescription =
NSLocalizedString("SearchSettingBrowserSuggestionCellDescription", tableName: "BraveShared", bundle: .module,
value: "Turn this on to include results from your History and Bookmarks when searching",
comment: "Label for showing browser suggestion setting description")
public static let searchSettingAddCustomEngineCellTitle =
NSLocalizedString("searchSettingAddCustomEngineCellTitle", tableName: "BraveShared", bundle: .module,
value: "Add Custom Search Engine",
Expand Down

0 comments on commit 542be8f

Please sign in to comment.