From 75e5ccc087a11d2a23b312ed9a433204e0c718ba Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Fri, 17 May 2024 19:36:55 +0600 Subject: [PATCH] Select all Find In Page text on cmd+f (#2783) Task/Issue URL: https://app.asana.com/0/1177771139624306/1207298392719916/f --- DuckDuckGo/Common/Extensions/NSTextFieldExtension.swift | 4 ++++ DuckDuckGo/FindInPage/FindInPageViewController.swift | 7 ++++++- DuckDuckGo/NavigationBar/View/AddressBarTextField.swift | 4 ---- DuckDuckGo/Tab/TabExtensions/FindInPageTabExtension.swift | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/DuckDuckGo/Common/Extensions/NSTextFieldExtension.swift b/DuckDuckGo/Common/Extensions/NSTextFieldExtension.swift index 563c7c1804..9b37797f7b 100644 --- a/DuckDuckGo/Common/Extensions/NSTextFieldExtension.swift +++ b/DuckDuckGo/Common/Extensions/NSTextFieldExtension.swift @@ -21,6 +21,10 @@ import Common extension NSTextField { + var isFirstResponder: Bool { + window?.firstResponder == currentEditor() + } + static func label(titled title: String) -> NSTextField { let label = NSTextField(string: title) diff --git a/DuckDuckGo/FindInPage/FindInPageViewController.swift b/DuckDuckGo/FindInPage/FindInPageViewController.swift index 142d9c1f18..727b84e82f 100644 --- a/DuckDuckGo/FindInPage/FindInPageViewController.swift +++ b/DuckDuckGo/FindInPage/FindInPageViewController.swift @@ -102,7 +102,12 @@ final class FindInPageViewController: NSViewController { } func makeMeFirstResponder() { - textField.makeMeFirstResponder() + if textField.isFirstResponder { + // select all on Cmd+F while editing + textField.currentEditor()?.selectAll(nil) + } else { + textField.makeMeFirstResponder() + } } private func subscribeToModelChanges() { diff --git a/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift b/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift index 8248039994..943f6a8e66 100644 --- a/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift +++ b/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift @@ -51,10 +51,6 @@ final class AddressBarTextField: NSTextField { tabCollectionViewModel.isBurner } - var isFirstResponder: Bool { - window?.firstResponder == currentEditor() - } - private var suggestionResultCancellable: AnyCancellable? private var selectedSuggestionViewModelCancellable: AnyCancellable? private var selectedTabViewModelCancellable: AnyCancellable? diff --git a/DuckDuckGo/Tab/TabExtensions/FindInPageTabExtension.swift b/DuckDuckGo/Tab/TabExtensions/FindInPageTabExtension.swift index c0c5d59bad..ada3a260c4 100644 --- a/DuckDuckGo/Tab/TabExtensions/FindInPageTabExtension.swift +++ b/DuckDuckGo/Tab/TabExtensions/FindInPageTabExtension.swift @@ -219,7 +219,7 @@ extension FindInPageTabExtension: NavigationResponder { } func navigation(_ navigation: Navigation, didSameDocumentNavigationOf navigationType: WKSameDocumentNavigationType) { - if case .sessionStateReplace = navigationType { + if [.sessionStatePush, .sessionStatePop].contains(navigationType) { close() } }