Skip to content

Commit

Permalink
Address bar refactoring (#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx authored Sep 14, 2023
1 parent 800ff95 commit b3229e5
Show file tree
Hide file tree
Showing 16 changed files with 1,143 additions and 624 deletions.
34 changes: 22 additions & 12 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,6 @@
3706FE0F293F661700E42796 /* CSVLoginExporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B723E0426B0003E00E14D75 /* CSVLoginExporterTests.swift */; };
3706FE10293F661700E42796 /* TestNavigationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6DA06E02913AEDB00225DE2 /* TestNavigationDelegate.swift */; };
3706FE11293F661700E42796 /* URLSuggestedFilenameTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8553FF51257523760029327F /* URLSuggestedFilenameTests.swift */; };
3706FE12293F661700E42796 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AADE11BF26D916D70032D8A7 /* StringExtensionTests.swift */; };
3706FE13293F661700E42796 /* ConfigurationStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85AC3B4825DAC9BD00C7D2AA /* ConfigurationStorageTests.swift */; };
3706FE14293F661700E42796 /* DownloadListStoreMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B693956026F1C1BC0015B914 /* DownloadListStoreMock.swift */; };
3706FE15293F661700E42796 /* PrivacyIconViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA91F83827076F1900771A0D /* PrivacyIconViewModelTests.swift */; };
Expand Down Expand Up @@ -2419,7 +2418,6 @@
AAD8078727B3F45600CF7703 /* WebsiteBreakage.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAD8078627B3F45600CF7703 /* WebsiteBreakage.swift */; };
AAD86E52267A0DFF005C11BE /* UpdateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAD86E51267A0DFF005C11BE /* UpdateController.swift */; };
AADCBF3A26F7C2CE00EF67A8 /* LottieAnimationCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = AADCBF3926F7C2CE00EF67A8 /* LottieAnimationCache.swift */; };
AADE11C026D916D70032D8A7 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AADE11BF26D916D70032D8A7 /* StringExtensionTests.swift */; };
AAE246F32709EF3B00BEEAEE /* FirePopoverCollectionViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE246F12709EF3B00BEEAEE /* FirePopoverCollectionViewItem.swift */; };
AAE246F42709EF3B00BEEAEE /* FirePopoverCollectionViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = AAE246F22709EF3B00BEEAEE /* FirePopoverCollectionViewItem.xib */; };
AAE246F6270A3D3000BEEAEE /* FirePopoverCollectionViewHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = AAE246F5270A3D3000BEEAEE /* FirePopoverCollectionViewHeader.xib */; };
Expand Down Expand Up @@ -2496,6 +2494,9 @@
B60C6F8B29B1CAC0007BFAA8 /* FileManagerTempDirReplacement.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60C6F8329B1BAD3007BFAA8 /* FileManagerTempDirReplacement.swift */; };
B60C6F8D29B200AB007BFAA8 /* SavePanelAccessoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60C6F8C29B200AB007BFAA8 /* SavePanelAccessoryView.swift */; };
B60C6F8E29B200AB007BFAA8 /* SavePanelAccessoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60C6F8C29B200AB007BFAA8 /* SavePanelAccessoryView.swift */; };
B60D64492AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60D64482AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift */; };
B60D644A2AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60D64482AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift */; };
B60D644B2AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60D64482AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift */; };
B6106BA026A7BE0B0013B453 /* PermissionManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106B9F26A7BE0B0013B453 /* PermissionManagerTests.swift */; };
B6106BA726A7BECC0013B453 /* PermissionAuthorizationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106BA526A7BEC80013B453 /* PermissionAuthorizationQuery.swift */; };
B6106BAB26A7BF1D0013B453 /* PermissionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106BAA26A7BF1D0013B453 /* PermissionType.swift */; };
Expand Down Expand Up @@ -2601,6 +2602,9 @@
B662D3D92755D7AD0035D4D6 /* PixelStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B662D3D82755D7AD0035D4D6 /* PixelStoreTests.swift */; };
B662D3DE275613BB0035D4D6 /* EncryptionKeyStoreMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B662D3DD275613BB0035D4D6 /* EncryptionKeyStoreMock.swift */; };
B662D3DF275616FF0035D4D6 /* EncryptionKeyStoreMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B662D3DD275613BB0035D4D6 /* EncryptionKeyStoreMock.swift */; };
B6676BE12AA986A700525A21 /* AddressBarTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6676BE02AA986A700525A21 /* AddressBarTextEditor.swift */; };
B6676BE22AA986A700525A21 /* AddressBarTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6676BE02AA986A700525A21 /* AddressBarTextEditor.swift */; };
B6676BE32AA986A700525A21 /* AddressBarTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6676BE02AA986A700525A21 /* AddressBarTextEditor.swift */; };
B6685E3D29A602D90043D2EE /* ExternalAppSchemeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B687B7CB2947A1E9001DEA6F /* ExternalAppSchemeHandler.swift */; };
B6685E3F29A606190043D2EE /* WorkspaceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6685E3E29A606190043D2EE /* WorkspaceProtocol.swift */; };
B6685E4029A606190043D2EE /* WorkspaceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6685E3E29A606190043D2EE /* WorkspaceProtocol.swift */; };
Expand Down Expand Up @@ -3747,7 +3751,6 @@
AAD86E502678D104005C11BE /* DuckDuckGoCI.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DuckDuckGoCI.entitlements; sourceTree = "<group>"; };
AAD86E51267A0DFF005C11BE /* UpdateController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateController.swift; sourceTree = "<group>"; };
AADCBF3926F7C2CE00EF67A8 /* LottieAnimationCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LottieAnimationCache.swift; sourceTree = "<group>"; };
AADE11BF26D916D70032D8A7 /* StringExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = "<group>"; };
AAE246F12709EF3B00BEEAEE /* FirePopoverCollectionViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirePopoverCollectionViewItem.swift; sourceTree = "<group>"; };
AAE246F22709EF3B00BEEAEE /* FirePopoverCollectionViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FirePopoverCollectionViewItem.xib; sourceTree = "<group>"; };
AAE246F5270A3D3000BEEAEE /* FirePopoverCollectionViewHeader.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FirePopoverCollectionViewHeader.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3791,6 +3794,7 @@
B60C6F8029B1B4AD007BFAA8 /* TestRunHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestRunHelper.swift; sourceTree = "<group>"; };
B60C6F8329B1BAD3007BFAA8 /* FileManagerTempDirReplacement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManagerTempDirReplacement.swift; sourceTree = "<group>"; };
B60C6F8C29B200AB007BFAA8 /* SavePanelAccessoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavePanelAccessoryView.swift; sourceTree = "<group>"; };
B60D64482AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressBarTextSelectionNavigation.swift; sourceTree = "<group>"; };
B6106B9D26A565DA0013B453 /* BundleExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleExtension.swift; sourceTree = "<group>"; };
B6106B9F26A7BE0B0013B453 /* PermissionManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionManagerTests.swift; sourceTree = "<group>"; };
B6106BA526A7BEC80013B453 /* PermissionAuthorizationQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionAuthorizationQuery.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3867,6 +3871,7 @@
B66260E529ACAE4B00E9E3EE /* NavigationHotkeyHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationHotkeyHandler.swift; sourceTree = "<group>"; };
B662D3D82755D7AD0035D4D6 /* PixelStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PixelStoreTests.swift; sourceTree = "<group>"; };
B662D3DD275613BB0035D4D6 /* EncryptionKeyStoreMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionKeyStoreMock.swift; sourceTree = "<group>"; };
B6676BE02AA986A700525A21 /* AddressBarTextEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressBarTextEditor.swift; sourceTree = "<group>"; };
B6685E3E29A606190043D2EE /* WorkspaceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceProtocol.swift; sourceTree = "<group>"; };
B6685E4129A61C460043D2EE /* DownloadsTabExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadsTabExtension.swift; sourceTree = "<group>"; };
B66B9C5B29A5EBAD0010E8F3 /* NavigationActionExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationActionExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6480,15 +6485,17 @@
isa = PBXGroup;
children = (
AA7EB6EE27E880EA00036718 /* Animations */,
85589E8C27BBBB870038AD11 /* NavigationBar.storyboard */,
AA68C3D22490ED62001B8783 /* NavigationBarViewController.swift */,
14D9B8F924F7E089000D4D13 /* AddressBarViewController.swift */,
AABEE6AE24AD22B90043105B /* AddressBarTextField.swift */,
AAC5E4F525D6BF2C007F5990 /* AddressBarButtonsViewController.swift */,
AAC5E4F025D6BF10007F5990 /* AddressBarButton.swift */,
AAA0CC32252F181A0079BC96 /* NavigationButtonMenuDelegate.swift */,
AAC5E4F525D6BF2C007F5990 /* AddressBarButtonsViewController.swift */,
AABEE6AE24AD22B90043105B /* AddressBarTextField.swift */,
B6676BE02AA986A700525A21 /* AddressBarTextEditor.swift */,
B60D64482AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift */,
14D9B8F924F7E089000D4D13 /* AddressBarViewController.swift */,
AAA0CC462533833C0079BC96 /* MoreOptionsMenu.swift */,
85589E8C27BBBB870038AD11 /* NavigationBar.storyboard */,
AAA0CC32252F181A0079BC96 /* NavigationButtonMenuDelegate.swift */,
85012B0129133F9F003D0DCC /* NavigationBarPopovers.swift */,
AA68C3D22490ED62001B8783 /* NavigationBarViewController.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -7076,7 +7083,6 @@
B67C6C462654C643006C872E /* FileManagerExtensionTests.swift */,
1DA6D0FF2A1FF9DC00540406 /* HTTPCookieTests.swift */,
B6C0B24526E9CB190031CB7F /* RunLoopExtensionTests.swift */,
AADE11BF26D916D70032D8A7 /* StringExtensionTests.swift */,
85F69B3B25EDE81F00978E59 /* URLExtensionTests.swift */,
4B8AD0B027A86D9200AE44D6 /* WKWebsiteDataStoreExtensionTests.swift */,
B6AA64722994B43300D99CD6 /* FutureExtensionTests.swift */,
Expand Down Expand Up @@ -9015,6 +9021,7 @@
3192A09C2A4C4CFF0084EA89 /* CookieConsentPopoverManager.swift in Sources */,
3192A09D2A4C4CFF0084EA89 /* PasswordManagementIdentityItemView.swift in Sources */,
3192A09E2A4C4CFF0084EA89 /* ProgressExtension.swift in Sources */,
B60D644B2AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift in Sources */,
3192A09F2A4C4CFF0084EA89 /* CSVParser.swift in Sources */,
3192A0A02A4C4CFF0084EA89 /* PixelDataModel.xcdatamodeld in Sources */,
3192A0A12A4C4CFF0084EA89 /* PrivacyDashboardWebView.swift in Sources */,
Expand Down Expand Up @@ -9226,6 +9233,7 @@
3192A1652A4C4CFF0084EA89 /* PasswordManagementLoginModel.swift in Sources */,
BB5CB0A12A7AD59D00B312D1 /* NetworkProtectionDebugUtilities.swift in Sources */,
3192A1662A4C4CFF0084EA89 /* TabViewModel.swift in Sources */,
B6676BE32AA986A700525A21 /* AddressBarTextEditor.swift in Sources */,
3192A1672A4C4CFF0084EA89 /* TabDragAndDropManager.swift in Sources */,
3192A1682A4C4CFF0084EA89 /* NSNotificationName+Favicons.swift in Sources */,
3192A1692A4C4CFF0084EA89 /* PinningManager.swift in Sources */,
Expand Down Expand Up @@ -9425,6 +9433,7 @@
3706FA93293F65D500E42796 /* WKWebView+Download.swift in Sources */,
3706FA94293F65D500E42796 /* TabShadowConfig.swift in Sources */,
3706FA97293F65D500E42796 /* WindowDraggingView.swift in Sources */,
B60D644A2AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift in Sources */,
3706FA98293F65D500E42796 /* SecureVaultSorting.swift in Sources */,
3706FA99293F65D500E42796 /* PreferencesSidebarModel.swift in Sources */,
3706FA9A293F65D500E42796 /* DuckPlayerURLExtension.swift in Sources */,
Expand Down Expand Up @@ -9578,6 +9587,7 @@
3706FB1D293F65D500E42796 /* StatisticsLoader.swift in Sources */,
3793FDD829535EBA00A2E28F /* Assertions.swift in Sources */,
3706FB1E293F65D500E42796 /* WebsiteBreakageReporter.swift in Sources */,
B6676BE22AA986A700525A21 /* AddressBarTextEditor.swift in Sources */,
3706FB1F293F65D500E42796 /* PrivacyPreferencesModel.swift in Sources */,
3706FB20293F65D500E42796 /* LocalUnprotectedDomains.swift in Sources */,
3707C719294B5D0F00682A9F /* HoveredLinkTabExtension.swift in Sources */,
Expand Down Expand Up @@ -10114,7 +10124,6 @@
3706FE10293F661700E42796 /* TestNavigationDelegate.swift in Sources */,
3706FE11293F661700E42796 /* URLSuggestedFilenameTests.swift in Sources */,
B6F56569299A414300A04298 /* WKWebViewMockingExtension.swift in Sources */,
3706FE12293F661700E42796 /* StringExtensionTests.swift in Sources */,
3706FE13293F661700E42796 /* ConfigurationStorageTests.swift in Sources */,
3706FE14293F661700E42796 /* DownloadListStoreMock.swift in Sources */,
3706FE15293F661700E42796 /* PrivacyIconViewModelTests.swift in Sources */,
Expand Down Expand Up @@ -10537,6 +10546,7 @@
B68458CD25C7EB9000DC17B6 /* WKWebViewConfigurationExtensions.swift in Sources */,
85AC7ADD27BEB6EE00FFB69B /* HomePageDefaultBrowserModel.swift in Sources */,
AAC30A26268DFEE200D2D9CD /* CrashReporter.swift in Sources */,
B60D64492AAF1B7C00B26F50 /* AddressBarTextSelectionNavigation.swift in Sources */,
3184AC6D288F29D800C35E4B /* BadgeNotificationAnimationModel.swift in Sources */,
857FFEC027D239DC00415E7A /* HyperLink.swift in Sources */,
37445F992A1566420029F789 /* SyncDataProviders.swift in Sources */,
Expand Down Expand Up @@ -10581,6 +10591,7 @@
85589E8027BBB8630038AD11 /* AddEditFavoriteWindow.swift in Sources */,
1D6216B229069BBF00386B2C /* BWKeyStorage.swift in Sources */,
AA7E919F287872EA00AB6B62 /* VisitViewModel.swift in Sources */,
B6676BE12AA986A700525A21 /* AddressBarTextEditor.swift in Sources */,
B69B503B2726A12500758A2B /* Atb.swift in Sources */,
B6C0BB6A29AF1C7000AE8E3C /* BrowserTabView.swift in Sources */,
B6B1E88026D5DA9B0062C350 /* DownloadsViewController.swift in Sources */,
Expand Down Expand Up @@ -11211,7 +11222,6 @@
56D145E829E6BB6300E3488A /* CapturingDataImportProvider.swift in Sources */,
B630793526731BC400DCEE41 /* URLSuggestedFilenameTests.swift in Sources */,
B603974E29C1F93600902A34 /* TabPermissionsTests.swift in Sources */,
AADE11C026D916D70032D8A7 /* StringExtensionTests.swift in Sources */,
85AC3B4925DAC9BD00C7D2AA /* ConfigurationStorageTests.swift in Sources */,
B693956126F1C1BC0015B914 /* DownloadListStoreMock.swift in Sources */,
AA91F83927076F1900771A0D /* PrivacyIconViewModelTests.swift in Sources */,
Expand Down
15 changes: 11 additions & 4 deletions DuckDuckGo/Common/Extensions/NSMenuExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ extension NSMenu {
}
}

func index(ofItemWithIdentifier id: String) -> Int? {
guard let item = items.first(where: { $0.identifier?.rawValue == id }) else { return nil }
return index(of: item)
func indexOfItem(withIdentifier id: String) -> Int? {
return items.enumerated().first(where: { $0.element.identifier?.rawValue == id })?.offset
}

func item(with identifier: WKMenuItemIdentifier) -> NSMenuItem? {
return index(ofItemWithIdentifier: identifier.rawValue).map { self.items[$0] }
return indexOfItem(withIdentifier: identifier.rawValue).map { self.items[$0] }
}

func indexOfItem(with action: Selector) -> Int? {
return items.enumerated().first(where: { $0.element.action == action })?.offset
}

func item(with action: Selector) -> NSMenuItem? {
return indexOfItem(with: action).map { self.items[$0] }
}

func replaceItem(at index: Int, with newItem: NSMenuItem) {
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Common/Extensions/NSPasteboardExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.
//

import AppKit
import Foundation

extension NSPasteboard {
Expand Down
13 changes: 0 additions & 13 deletions DuckDuckGo/Common/Extensions/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,10 @@ extension String {

// MARK: - General

func nsRange(from range: Range<String.Index>? = nil) -> NSRange {
if let range = range {
return NSRange(location: self[..<range.lowerBound].utf16.count,
length: self[range].utf16.count)
} else {
return NSRange(location: 0, length: utf16.count)
}
}

func truncated(length: Int, trailing: String = "") -> String {
return (self.count > length) ? self.prefix(length) + trailing : self
}

subscript (_ range: NSRange) -> Self {
.init(self[utf16.index(startIndex, offsetBy: range.lowerBound) ..< utf16.index(startIndex, offsetBy: range.upperBound)])
}

func escapedJavaScriptString() -> String {
self.replacingOccurrences(of: "\\", with: "\\\\")
.replacingOccurrences(of: "\"", with: "\\\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.
//

import BrowserServicesKit
import Cocoa
import Combine
import Common
Expand Down Expand Up @@ -1040,7 +1041,7 @@ extension URL {
var isLocalURL: Bool {
if let host = self.host {
for regex in Self.compiledRegexes
where regex.firstMatch(in: host, options: [], range: NSRange(location: 0, length: host.utf16.count)) != nil {
where regex.firstMatch(in: host, options: [], range: host.fullRange) != nil {
return true
}
}
Expand Down
Loading

0 comments on commit b3229e5

Please sign in to comment.