Web Inspector: Search: populate the search field with the current selection when...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2020 20:02:17 +0000 (20:02 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Apr 2020 20:02:17 +0000 (20:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=210207

Reviewed by Timothy Hatcher.

Add a setting to control whether the global search (⇧⌘F) should be populated by the current
selection (if it exists), allowing for a quicker flow for "show me everywhere this exists".

* UserInterface/Base/Setting.js:
* UserInterface/Views/SettingsTabContentView.js:
(WI.SettingsTabContentView.prototype._createGeneralSettingsView):

* UserInterface/Base/Main.js:
(WI._focusSearchField)

* Localizations/en.lproj/localizedStrings.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259748 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Base/Setting.js
Source/WebInspectorUI/UserInterface/Views/SettingsTabContentView.js

index 069fc27..b6d14c3 100644 (file)
@@ -1,5 +1,24 @@
 2020-04-08  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Search: populate the search field with the current selection when using the global search shortcut
+        https://bugs.webkit.org/show_bug.cgi?id=210207
+
+        Reviewed by Timothy Hatcher.
+
+        Add a setting to control whether the global search (⇧⌘F) should be populated by the current
+        selection (if it exists), allowing for a quicker flow for "show me everywhere this exists".
+
+        * UserInterface/Base/Setting.js:
+        * UserInterface/Views/SettingsTabContentView.js:
+        (WI.SettingsTabContentView.prototype._createGeneralSettingsView):
+
+        * UserInterface/Base/Main.js:
+        (WI._focusSearchField)
+
+        * Localizations/en.lproj/localizedStrings.js:
+
+2020-04-08  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Storage: cannot clear out multiple or all local storage entries
         https://bugs.webkit.org/show_bug.cgi?id=209867
 
index 2375f10..53810e4 100644 (file)
@@ -615,6 +615,8 @@ localizedStrings["General"] = "General";
 localizedStrings["Getter"] = "Getter";
 localizedStrings["Global Code"] = "Global Code";
 localizedStrings["Global Lexical Environment"] = "Global Lexical Environment";
+/* Settings tab checkbox label for whether the global search should populate from the current selection. */
+localizedStrings["Global Search From Selection @ Settings"] = "%s from selection";
 localizedStrings["Global Variables"] = "Global Variables";
 localizedStrings["Grammar"] = "Grammar";
 /* Name of Graphics Tab */
index 300869c..ac399ab 100644 (file)
@@ -1542,12 +1542,23 @@ WI.debuggerStepOut = function(event)
 
 WI._focusSearchField = function(event)
 {
+    let searchQuery = "";
+
+    if (WI.settings.searchFromSelection.value) {
+        let selection = window.getSelection();
+        if (selection.type === "Range" || !selection.isCollapsed)
+            searchQuery = selection.toString().removeWordBreakCharacters();
+    }
+
     WI.tabBrowser.showTabForContentView(WI._searchTabContentView, {
         // Classify this as a keyboard shortcut, as the only other way to get to Search Tab is via TabBar itself.
         initiatorHint: WI.TabBrowser.TabNavigationInitiator.KeyboardShortcut,
     });
 
     WI._searchTabContentView.focusSearchField();
+
+    if (searchQuery)
+        WI._searchTabContentView.performSearch(searchQuery);
 };
 
 WI._focusChanged = function(event)
index 99d7ae8..b1a058b 100644 (file)
@@ -193,6 +193,7 @@ WI.settings = {
     indentWithTabs: new WI.Setting("indent-with-tabs", false),
     resourceCachingDisabled: new WI.Setting("disable-resource-caching", false),
     searchCaseSensitive: new WI.Setting("search-case-sensitive", false),
+    searchFromSelection: new WI.Setting("search-from-selection", false),
     searchRegularExpression: new WI.Setting("search-regular-expression", false),
     selectedNetworkDetailContentViewIdentifier: new WI.Setting("network-detail-content-view-identifier", "preview"),
     sourceMapsEnabled: new WI.Setting("source-maps-enabled", true),
index 99a3d57..486b298 100644 (file)
@@ -251,6 +251,7 @@ WI.SettingsTabContentView = class SettingsTabContentView extends WI.TabContentVi
         let searchGroup = generalSettingsView.addGroup(WI.UIString("Search:", "Search: @ Settings", "Settings tab label for search related settings"));
         searchGroup.addSetting(WI.settings.searchCaseSensitive, WI.UIString("Case Sensitive", "Case Sensitive @ Settings", "Settings tab checkbox label for whether searches should be case sensitive."));
         searchGroup.addSetting(WI.settings.searchRegularExpression, WI.UIString("Regular Expression", "Regular Expression @ Settings", "Settings tab checkbox label for whether searches should be treated as regular expressions."));
+        searchGroup.addSetting(WI.settings.searchFromSelection, WI.UIString("%s from selection", "Global Search From Selection @ Settings", "Settings tab checkbox label for whether the global search should populate from the current selection.").format(WI.searchKeyboardShortcut.displayName));
 
         generalSettingsView.addSeparator();