Bug 686487 - Ctrl+K should open a new global search tab if searchbox is not available. r=asuth
Toolbar customization, hidden toolbars, but gloda enabled. (started by Wei Zhang, polished by aceman)
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -3531,43 +3531,78 @@ function SendMDNResponse()
gMessageNotificationBar.mdnGenerator.userAgreed();
}
function IgnoreMDNResponse()
{
gMessageNotificationBar.mdnGenerator.userDeclined();
}
+/***
+ * Focus the gloda global search input box on current tab, or,
+ * if the search box is hidden, open a new gloda search tab
+ * and focus its search box.
+ */
function QuickSearchFocus()
{
+ if (!Services.prefs.getBoolPref("mailnews.database.global.indexer.enabled")) {
+ // If gloda is disabled, do nothing.
+ return;
+ }
+
let tabmail = document.getElementById('tabmail');
+ if (!tabmail) {
+ // No tabmail element: This should never happen.
+ return;
+ }
// If we're currently viewing a Gloda tab, drill down to find the
// built-in search input, and select that.
- if (tabmail
- && tabmail.currentTabInfo.mode.name == "glodaFacet") {
+ if (tabmail.currentTabInfo.mode.name == "glodaFacet") {
let searchInput = tabmail.currentTabInfo
.panel
.querySelector(".remote-gloda-search");
if (searchInput)
searchInput.select();
return;
}
- if (tabmail && tabmail.currentTabInfo.mode.name == "chat") {
+ if (tabmail.currentTabInfo.mode.name == "chat") {
let searchInput = document.getElementById("IMSearchInput");
if (searchInput)
searchInput.select();
return;
}
- var quickSearchTextBox = document.getElementById('searchInput');
- if (quickSearchTextBox)
- quickSearchTextBox.select();
+ let newTab = true;
+ let globalSearchTextBox = document.getElementById("searchInput");
+ if (globalSearchTextBox) {
+ // Via toolbar customization, globalSearchTextBox can be in different places:
+ // Toolbars, tab bar, menu bar, etc. When the containing elements are hidden,
+ // the searchbox will also be hidden, so clientHeight and clientWidth of the
+ // searchbox or one of its parent will typically be zero and we can test for that.
+ // If globalSearchTextBox is hidden, use a new tab.
+ newTab = false;
+ let element = globalSearchTextBox;
+ while (element) {
+ if ((element.clientHeight == 0) || (element.clientWidth == 0))
+ newTab = true;
+ element = element.parentElement;
+ }
+ }
+
+ if (!newTab) {
+ // Focus and select global search box.
+ globalSearchTextBox.select();
+ } else {
+ // Open a new global search tab.
+ globalSearchTextBox.value = "";
+ globalSearchTextBox.doSearch(true);
+ }
}
/**
* Opens a search window with the given folder, or the displayed one if none is
* chosen.
*
* @param [aFolder] the folder to open the search window for, if different from
* the displayed one
--- a/mail/base/content/search.xml
+++ b/mail/base/content/search.xml
@@ -212,21 +212,21 @@
}
} catch (e) {
logException(e);
}
]]></body>
</method>
<method name="doSearch">
+ <parameter name="aEmpty"/> <!-- run the search even with empty string -->
<body><![CDATA[
Components.utils.import("resource://gre/modules/Services.jsm");
-
try {
- if (this.value) {
+ if (this.value || aEmpty) {
let tabmail = document.getElementById("tabmail");
// If the current tab is a gloda search tab, reset the value
// to the initial search value. Otherwise, clear it. This
// is the value that 3is going to be saved with the current
// tab when we switch back to it next.
let searchString = this.value;
if (tabmail.currentTabInfo.mode.name == "glodaFacet") {