Bug 1558574 - Re-add support for clickSelectsAll attribute on search-textbox. r=bgrins
authorTim Nguyen <ntim.bugs@gmail.com>
Thu, 13 Jun 2019 16:32:17 +0000
changeset 478707 2807c9fd659decb188eea7a6751db8daa499b318
parent 478706 4f05b6e71fb2ee1f48f4b61ae4aad9d3714f5075
child 478708 f758b5ccd0c069acc6e494ac77aeb430d8ea6b8f
push id36148
push usershindli@mozilla.com
push dateThu, 13 Jun 2019 21:50:57 +0000
treeherdermozilla-central@fcdbd2fce463 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1558574
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1558574 - Re-add support for clickSelectsAll attribute on search-textbox. r=bgrins 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;