Bug 1192486 - make completion work in any selected style editor; r=mratcliffe
authorTom Tromey <tromey@mozilla.com>
Wed, 11 Nov 2015 09:43:00 +0100
changeset 308689 9bd35d40fff9a9ee56c7fa4b0fae6e0dec802151
parent 308688 cfce9960cdb18258a6455b2dc607ae43f5aa2c2f
child 308690 53f9d55997a54967c53f7a56f02ddff2c16741dd
push id7514
push users.kaspari@gmail.com
push dateFri, 13 Nov 2015 14:12:41 +0000
reviewersmratcliffe
bugs1192486
milestone45.0a1
Bug 1192486 - make completion work in any selected style editor; r=mratcliffe
devtools/client/sourceeditor/autocomplete.js
devtools/client/styleeditor/test/autocomplete.html
devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
--- a/devtools/client/sourceeditor/autocomplete.js
+++ b/devtools/client/sourceeditor/autocomplete.js
@@ -9,16 +9,19 @@ const { AutocompletePopup } = require("d
 
 const CM_TERN_SCRIPTS = [
   "chrome://devtools/content/sourceeditor/codemirror/tern/tern.js",
   "chrome://devtools/content/sourceeditor/codemirror/hint/show-hint.js"
 ];
 
 const autocompleteMap = new WeakMap();
 
+// A simple way to give each popup its own panelId.
+var autocompleteCounter = 0;
+
 /**
  * Prepares an editor instance for autocompletion.
  */
 function initializeAutoCompletion(ctx, options = {}) {
   let { cm, ed, Editor } = ctx;
   if (autocompleteMap.has(ed)) {
     return;
   }
@@ -115,22 +118,27 @@ function initializeAutoCompletion(ctx, o
       insertPopupItem(ed, popup.selectedItem);
     }
 
     popup.hidePopup();
     ed.emit("popup-hidden"); // This event is used in tests.
     return true;
   }
 
+  // Give each popup a new name to avoid sharing the elements.
+  let panelId = "devtools_sourceEditorCompletePopup" + autocompleteCounter;
+  ++autocompleteCounter;
+
   let popup = new AutocompletePopup(win.parent.document, {
     position: "after_start",
     fixedWidth: true,
     theme: "auto",
     autoSelect: true,
-    onClick: insertSelectedPopupItem
+    onClick: insertSelectedPopupItem,
+    panelId: panelId
   });
 
   let cycle = (reverse) => {
     if (popup && popup.isOpen) {
       cycleSuggestions(ed, reverse == true);
       return;
     }
 
--- a/devtools/client/styleeditor/test/autocomplete.html
+++ b/devtools/client/styleeditor/test/autocomplete.html
@@ -1,12 +1,13 @@
 <!doctype html>
 <html>
 <head>
   <title>testcase for autocomplete testing</title>
+  <link rel="stylesheet" type="text/css" href="resources_inpage1.css"/>
   <style type="text/css">
   div {
     font-size: 4em;
   }
 
   div > span {
      text-decoration: underline;
   }
--- a/devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
@@ -96,17 +96,20 @@ var TEST_CASES = [
   ["VK_RIGHT"],
   ["VK_RIGHT"],
   ["VK_RIGHT"],
   ["Ctrl+Space", {total: 1, current: 0}],
 ];
 
 add_task(function* () {
   let { panel, ui } = yield openStyleEditorForURL(TESTCASE_URI);
-  let editor = yield ui.editors[0].getSourceEditor();
+
+  yield ui.selectStyleSheet(ui.editors[1].styleSheet);
+  let editor = yield ui.editors[1].getSourceEditor();
+
   let sourceEditor = editor.sourceEditor;
   let popup = sourceEditor.getAutocompletionPopup();
 
   yield SimpleTest.promiseFocus(panel.panelWindow);
 
   for (let index in TEST_CASES) {
     yield testState(index, sourceEditor, popup, panel.panelWindow);
     yield checkState(index, sourceEditor, popup);