Bug 1558574 - Re-add support for clickSelectsAll attribute on search-textbox. r=bgrins a=jcristau
authorTim Nguyen <ntim.bugs@gmail.com>
Mon, 17 Jun 2019 18:35:23 +0300
changeset 533917 e61f8c9dad77696aacec8206ac567d98de3ba6f5
parent 533916 c6cf0c6f2c8933b53f6112865be891feb549b301
child 533918 193e4087e4c1d2d7a27c3bf4c932a97d03a5b2d3
push id11461
push userdluca@mozilla.com
push dateMon, 17 Jun 2019 16:40:33 +0000
treeherdermozilla-beta@19b174fe464e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins, jcristau
bugs1558574
milestone68.0
Bug 1558574 - Re-add support for clickSelectsAll attribute on search-textbox. r=bgrins a=jcristau Reviewers: bgrins Reviewed By: bgrins Bug #: 1558574 Differential Revision: https://phabricator.services.mozilla.com/D34906
toolkit/content/widgets/search-textbox.js
--- a/toolkit/content/widgets/search-textbox.js
+++ b/toolkit/content/widgets/search-textbox.js
@@ -29,16 +29,23 @@ class MozSearchTextbox extends MozXULEle
           return this.inputField[property];
         },
         set(val) {
           return this.inputField[property] = val;
         },
       });
     }
 
+    this.addEventListener("click", (event) => {
+      if (this.clickSelectsAll &&
+          document.activeElement == this.inputField &&
+          this.inputField.selectionStart == this.inputField.selectionEnd)
+      this.editor.selectAll();
+    });
+
     this.addEventListener("input", (event) => {
       if (this.searchButton) {
         this._searchIcons.selectedIndex = 0;
         return;
       }
       if (this._timer) {
         clearTimeout(this._timer);
       }
@@ -169,16 +176,28 @@ class MozSearchTextbox extends MozXULEle
     else this.removeAttribute("disabled");
     return val;
   }
 
   get disabled() {
     return this.inputField.disabled;
   }
 
+  get clickSelectsAll() {
+    return this.getAttribute("clickSelectsAll") == "true";
+  }
+
+  set clickSelectsAll(val) {
+    if (val) {
+      this.setAttribute("clickSelectsAll", "true");
+    } else {
+      this.removeAttribute("clickSelectsAll");
+    }
+  }
+
   reset() {
     this.value = this.defaultValue;
     // XXX: Is this still needed ?
     try {
       this.editor.transactionManager.clear();
       return true;
     } catch (e) {}
     return false;