Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Switch to tab implementation #3660

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Arrow-Right-12.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Window-Tabbed-16D 1.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
5 changes: 5 additions & 0 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ struct UserText {
static let searchDuckDuckGoSuffix = NSLocalizedString("address.bar.search.suffix",
value: "Search DuckDuckGo",
comment: "Suffix of searched terms in address bar. Example: best watching machine . Search DuckDuckGo")
static let duckDuckGoSearchSuffix = NSLocalizedString("address.bar.search.open.tab.suffix",
value: "DuckDuckGo Search",
comment: "Suffix of DuckDuckGo Search open tab suggestion. Example: cats – DuckDuckGo Search")
static let addressBarVisitSuffix = NSLocalizedString("address.bar.visit.suffix",
value: "Visit",
comment: "Address bar suffix of possibly visited website. Example: spreadprivacy.com . Visit spreadprivacy.com")
Expand Down Expand Up @@ -1435,4 +1438,6 @@ struct UserText {
static let homePagePromotionFreemiumDBPPostScanEngagementButtonTitle = "View Results"

static let removeSuggestionTooltip = NSLocalizedString("remove.suggestion.tooltip", value: "Remove from browsing history", comment: "Tooltip for the button which removes the history entry from the history")

static let switchToTab = NSLocalizedString("switch.to.tab", value: "Switch to Tab", comment: "Suggestion to switch to an open tab button title")
}
2 changes: 1 addition & 1 deletion DuckDuckGo/HomePage/Model/HomePageAddressBarModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extension HomePage.Models {
return AddressBarViewController(
coder: coder,
tabCollectionViewModel: tabCollectionViewModel,
isBurner: tabCollectionViewModel.isBurner,
burnerMode: tabCollectionViewModel.burnerMode,
popovers: nil,
isSearchBox: true
)
Expand Down
24 changes: 24 additions & 0 deletions DuckDuckGo/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,18 @@
}
}
},
"address.bar.search.open.tab.suffix" : {
"comment" : "Suffix of DuckDuckGo Search open tab suggestion. Example: cats – DuckDuckGo Search",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "DuckDuckGo Search"
}
}
}
},
"address.bar.search.suffix" : {
"comment" : "Suffix of searched terms in address bar. Example: best watching machine . Search DuckDuckGo",
"extractionState" : "extracted_with_value",
Expand Down Expand Up @@ -63955,6 +63967,18 @@
}
}
},
"switch.to.tab" : {
"comment" : "Suggestion to switch to an open tab button title",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Switch to Tab"
}
}
}
},
"sync.promo.bookmarks.message" : {
"comment" : "Message for the Sync Promotion banner when user has bookmarks that can be synced",
"extractionState" : "extracted_with_value",
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/MainWindow/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ final class MainViewController: NSViewController {
}()

navigationBarViewController = NavigationBarViewController.create(tabCollectionViewModel: tabCollectionViewModel,
isBurner: isBurner,
networkProtectionPopoverManager: networkProtectionPopoverManager,
networkProtectionStatusReporter: networkProtectionStatusReporter,
autofillPopoverPresenter: autofillPopoverPresenter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,12 @@ final class AddressBarButtonsViewController: NSViewController {
imageButton.image = .web
case .browsing:
imageButton.image = tabViewModel.favicon
case .editing(isUrl: true):
case .editing(.url):
imageButton.image = .web
case .editing(isUrl: false):
case .editing(.text):
imageButton.image = .search
case .editing(.openTabSuggestion):
imageButton.image = .openTabSuggestion
default:
imageButton.image = nil
}
Expand Down
55 changes: 35 additions & 20 deletions DuckDuckGo/NavigationBar/View/AddressBarTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ final class AddressBarTextField: NSTextField {
PixelKit.fire(autocompletePixel)
}

if NSApp.isCommandPressed {
if case .internalPage(title: let title, url: let url) = suggestion,
url == .bookmarks || url.isSettingsURL {
// when choosing an internal page suggestion preffer already open matching tab
switchTo(OpenTab(title: title, url: url))
} else if case .openTab(let title, url: let url) = suggestion {
switchTo(OpenTab(title: title, url: url))
} else if NSApp.isCommandPressed {
openNew(NSApp.isOptionPressed ? .window : .tab, selected: NSApp.isShiftPressed, suggestion: suggestion)
} else {
hideSuggestionWindow()
Expand Down Expand Up @@ -486,6 +492,10 @@ final class AddressBarTextField: NSTextField {
}
}

private func switchTo(_ tab: OpenTab) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we encapsulate this logic somewhere else? (standalone class maybe?) It is slightly confusing to have logic for switching tabs in AddressBarTextField

WindowControllersManager.shared.show(url: tab.url, source: .switchToOpenTab, newTab: true /* in case not found */)
}

private func makeUrl(suggestion: Suggestion?, stringValueWithoutSuffix: String, completion: @escaping (URL?, String, Bool) -> Void) {
let finalUrl: URL?
let userEnteredValue: String
Expand Down Expand Up @@ -890,8 +900,7 @@ extension AddressBarTextField {

case .bookmark(title: _, url: let url, isFavorite: _, allowedInTopHits: _),
.historyEntry(title: _, url: let url, allowedInTopHits: _),
.internalPage(title: _, url: let url),
.openTab(title: _, url: let url):
.internalPage(title: _, url: let url):
if let title = suggestionViewModel.title,
!title.isEmpty,
suggestionViewModel.autocompletionString != title {
Expand All @@ -901,7 +910,8 @@ extension AddressBarTextField {
} else {
self = .url(url)
}

case .openTab(title: _, url: let url):
self = .openTab(url)
case .unknown:
self = Suffix.search
}
Expand All @@ -911,6 +921,7 @@ extension AddressBarTextField {
case visit(host: String)
case url(URL)
case title(String)
case openTab(URL)

func toAttributedString(size: CGFloat, isBurner: Bool) -> NSAttributedString {
let suffixColor = isBurner ? NSColor.burnerAccent : NSColor.addressBarSuffix
Expand All @@ -922,6 +933,8 @@ extension AddressBarTextField {
}

static let searchSuffix = " – \(UserText.searchDuckDuckGoSuffix)"
static let searchOpenTabSuffix = " – \(UserText.duckDuckGoSearchSuffix)"
static let internalPageOpenTabSuffix = " – \(UserText.duckDuckGo)"
static let visitSuffix = " – \(UserText.addressBarVisitSuffix)"

var string: String {
Expand All @@ -930,14 +943,16 @@ extension AddressBarTextField {
return Self.searchSuffix
case .visit(host: let host):
return "\(Self.visitSuffix) \(host)"
case .url(let url):
if url.isDuckDuckGoSearch {
return Self.searchSuffix
} else {
return " – " + url.toString(decodePunycode: false,
dropScheme: true,
dropTrailingSlash: false)
}
case .openTab(let url) where url.isDuckDuckGoSearch:
return Self.searchOpenTabSuffix
case .openTab(let url) where url.isDuckURLScheme:
return Self.internalPageOpenTabSuffix
case .url(let url) where url.isDuckDuckGoSearch:
return Self.searchSuffix
case .url(let url), .openTab(let url):
return " – " + url.toString(decodePunycode: false,
dropScheme: true,
dropTrailingSlash: false)
case .title(let title):
return " – " + title
}
Expand Down Expand Up @@ -1037,14 +1052,14 @@ extension AddressBarTextField: NSTextFieldDelegate {
return true

case #selector(NSResponder.deleteBackward(_:)),
#selector(NSResponder.deleteForward(_:)),
#selector(NSResponder.deleteToMark(_:)),
#selector(NSResponder.deleteWordForward(_:)),
#selector(NSResponder.deleteWordBackward(_:)),
#selector(NSResponder.deleteToEndOfLine(_:)),
#selector(NSResponder.deleteToEndOfParagraph(_:)),
#selector(NSResponder.deleteToBeginningOfLine(_:)),
#selector(NSResponder.deleteBackwardByDecomposingPreviousCharacter(_:)):
#selector(NSResponder.deleteForward(_:)),
#selector(NSResponder.deleteToMark(_:)),
#selector(NSResponder.deleteWordForward(_:)),
#selector(NSResponder.deleteWordBackward(_:)),
#selector(NSResponder.deleteToEndOfLine(_:)),
#selector(NSResponder.deleteToEndOfParagraph(_:)),
#selector(NSResponder.deleteToBeginningOfLine(_:)),
#selector(NSResponder.deleteBackwardByDecomposingPreviousCharacter(_:)):

suggestionContainerViewModel?.clearSelection()
return false
Expand Down
Loading
Loading