Autocomplete popup should be displayed even if there's one matching item but the autocompletionText can't be displayed

RESOLVED FIXED in Firefox 63

Status

defect
P1
normal
RESOLVED FIXED
Last year
Last year

People

(Reporter: nchevobbe, Assigned: nchevobbe)

Tracking

unspecified
Firefox 63
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox63 fixed)

Details

(Whiteboard: [boogaloo-mvp])

Attachments

(1 attachment)

**Steps to reproduce**
1. Open the console
2. Enter the following `console.log()` and move the cursor inside the parenthesis
3. Then type `document.bo`
4. At this point, the input should be like `console.log(document.bo)`


**Expected results**

We can't show the completionText since there's some text _after_ the cursor,
so the popup should be still visible, even with only 1 item in it

**Actual results**

The autocompletion results only return "body", so the popup is hidden.

---


Marking this as depending on Bug 672733 since the code that needs to be modified is changed a bit in the patch in review there.
Priority: -- → P3
Whiteboard: [boogaloo-reserve]
This should mostly work (the test is failing because of cursor position though): 

```
diff --git a/devtools/client/webconsole/components/JSTerm.js b/devtools/client/webconsole/components/JSTerm.js
--- a/devtools/client/webconsole/components/JSTerm.js
+++ b/devtools/client/webconsole/components/JSTerm.js
@@ -1154,9 +1154,16 @@ class JSTerm extends Component {
     // - there is at least 2 matching results
     // - OR, if there's 1 result, but whose label does not start like the input (this can
     //   happen with insensitive search: `num` will match `Number`).
-    if (items.length >= minimumAutoCompleteLength || (
-      items.length === 1 && items[0].preLabel !== matchProp
-    )) {
+    // - OR, if there's 1 result, but we can't show the completionText (because there's
+    // some text after the cursor), unless the text in the popup is the same as the input.
+    if (items.length >= minimumAutoCompleteLength
+      || (items.length === 1 && items[0].preLabel !== matchProp)
+      || (
+        items.length === 1
+        && !this.canDisplayAutoCompletionText()
+        && items[0].label !== matchProp
+      )
+    ) {
       let popupAlignElement;
       let xOffset;
       let yOffset;
diff --git a/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_inside_text.js b/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_inside_text.js
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_inside_text.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_inside_text.js
@@ -87,19 +87,27 @@ async function performTests() {
   checkJsTermCursor(jsterm, expectedInput.length - 1, "cursor location is correct");
   ok(!getJsTermCompletionValue(jsterm), "there is no completion text");
 
-  info("Test TAB key when there is no autocomplete suggestion");
+  info("Test autocomplete inside parens");
   jsterm.setInputValue("dump()");
   EventUtils.synthesizeKey("KEY_ArrowLeft");
   const onAutocompleteUpdated = jsterm.once("autocomplete-updated");
   EventUtils.sendString("window.testBugA");
   await onAutocompleteUpdated;
+  ok(popup.isOpen, "popup is open");
+  ok(!getJsTermCompletionValue(jsterm), "there is no completion text");
+
+  info("Matching the completion proposal should close the popup");
+  onPopupClose = popup.once("popup-closed");
+  EventUtils.sendString("A");
+  await onPopupClose;
+
+  info("Test TAB key when there is no autocomplete suggestion");
   ok(!popup.isOpen, "popup is not open");
   ok(!getJsTermCompletionValue(jsterm), "there is no completion text");
 
   EventUtils.synthesizeKey("KEY_Tab");
-
-  expectedInput = "dump(window.testBugAA)";
-  is(jsterm.getInputValue(), "dump(window.testBugA\t)", "Tab inserted a tab char");
+  expectedInput = "dump(window.testBugAA\t)";
+  is(jsterm.getInputValue(), expectedInput, "completion was successful after Enter");
   checkJsTermCursor(jsterm, expectedInput.length - 1, "cursor location is correct");
 }
 ```
If the autocomplete only returns 1 item, we usually close the
popup and show the autocompletion text.
But in some cases the autocompletion text can be shown (e.g.
there's some text after the cursor). So we end up showing
nothing for the user, which is not ideal.
In such case, this patch ensures we do show the popup so the
user can autocomplete and save some keystrokes.

Depends on D4061
Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED
Priority: P3 → P1
Whiteboard: [boogaloo-reserve] → [boogaloo-mvp]
Comment on attachment 9004213 [details]
Bug 1485990 - Display 1-item-only autocomplete popup if autocompletion text can't be displayed; r=bgrins.

Brian Grinstead [:bgrins] has approved the revision.
Attachment #9004213 - Flags: review+
Pushed by nchevobbe@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c7c09f0fedf6
Display 1-item-only autocomplete popup if autocompletion text can't be displayed; r=bgrins.
https://hg.mozilla.org/mozilla-central/rev/c7c09f0fedf6
Status: ASSIGNED → RESOLVED
Closed: Last year
Resolution: --- → FIXED
Target Milestone: --- → Firefox 63
You need to log in before you can comment on or make changes to this bug.