Bug 1143742 - part3: multiline inplace-editor autocomplete behavior;r=gl draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 30 Mar 2016 22:58:41 +0200
changeset 346099 80195d4d45891552c0781208cf737f416828abc9
parent 346098 f2d36f113fb2af30050576b0b4a79bca4016e076
child 346100 0ed4c0139a31bb7cf1a4006418d91571a87271ab
push id14240
push userjdescottes@mozilla.com
push dateWed, 30 Mar 2016 23:01:44 +0000
reviewersgl
bugs1143742
milestone48.0a1
Bug 1143742 - part3: multiline inplace-editor autocomplete behavior;r=gl The default inplace-editor autocomplete behavior is not userfriendly when combined with a multiline inplace-editor. Navigating up/down might trigger an autocomplete suggestion. Also, the autocomplete popup is not displayed at the correct position and should take the multiline into account. MozReview-Commit-ID: JTiCQ3HK5bn
devtools/client/shared/inplace-editor.js
--- a/devtools/client/shared/inplace-editor.js
+++ b/devtools/client/shared/inplace-editor.js
@@ -1321,32 +1321,43 @@ InplaceEditor.prototype = {
                                               startCheckQuery.length);
         this._updateSize();
       }
 
       // Display the list of suggestions if there are more than one.
       if (finalList.length > 1) {
         // Calculate the popup horizontal offset.
         let indent = this.input.selectionStart - query.length;
-        let offset = indent * this.inputCharWidth;
+        let offset = indent * this.inputCharDimensions.width;
+        offset = this._isSingleLine() ? offset : 0;
 
         // Select the most relevantItem if autoInsert is allowed
         let selectedIndex = autoInsert ? mostRelevantIndex : -1;
 
         // Open the suggestions popup.
         this.popup.setItems(finalList);
         this.popup.openPopup(this.input, offset, 0, selectedIndex);
       } else {
         this.popup.hidePopup();
       }
       // This emit is mainly for the purpose of making the test flow simpler.
       this.emit("after-suggest");
       this._doValidation();
     }, 0);
   },
+
+  /**
+   * Check if the current input is displaying more than one line of text.
+   *
+   * @return {Boolean} true if the input has a single line of text
+   */
+  _isSingleLine: function() {
+    let inputRect = this.input.getBoundingClientRect();
+    return inputRect.height < 2 * this.inputCharDimensions.height;
+  },
 };
 
 /**
  * Copy text-related styles from one element to another.
  */
 function copyTextStyles(from, to) {
   let win = from.ownerDocument.defaultView;
   let style = win.getComputedStyle(from);