Bug 933015 - Attach Editor controller to the hidden textarea instead of a CM window. r=benvie
authorAnton Kovalyov <anton@mozilla.com>
Tue, 05 Nov 2013 10:30:19 -0800
changeset 167363 9b4b4c1b6dfe6ecfc00ec126dc28b99e2550dcf3
parent 167362 e3c81d8f02d30491e6ec35766230e4d1f953a4d7
child 167364 924d4a7b26d827dbaa1aca513198aa107d5ffdb1
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenvie
bugs933015
milestone27.0a2
Bug 933015 - Attach Editor controller to the hidden textarea instead of a CM window. r=benvie
browser/devtools/scratchpad/scratchpad.xul
browser/devtools/sourceeditor/editor.js
--- a/browser/devtools/scratchpad/scratchpad.xul
+++ b/browser/devtools/scratchpad/scratchpad.xul
@@ -30,17 +30,17 @@
 
 <script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
 <script type="application/javascript" src="chrome://browser/content/devtools/scratchpad.js"/>
 
 
 <script type="application/javascript">
   function goUpdateSourceEditorMenuItems() {
     goUpdateGlobalEditMenuItems();
-    let commands = ['cmd_undo', 'cmd_redo', 'cmd_cut', 'cmd_paste', 'cmd_delete', 'cmd_findAgain'];
+    let commands = ['cmd_undo', 'cmd_redo', 'cmd_delete', 'cmd_findAgain'];
     commands.forEach(goUpdateCommand);
   }
 </script>
 
 <commandset id="editMenuCommands"/>
 
 <commandset id="sourceEditorCommands">
   <command id="cmd_gotoLine" oncommand="goDoCommand('cmd_gotoLine')"/>
--- a/browser/devtools/sourceeditor/editor.js
+++ b/browser/devtools/sourceeditor/editor.js
@@ -180,18 +180,17 @@ Editor.prototype = {
    * the only argument 'el'. This method actually creates and loads
    * CodeMirror and all its dependencies.
    *
    * This method is asynchronous and returns a promise.
    */
   appendTo: function (el) {
     let def = promise.defer();
     let cm  = editors.get(this);
-    let doc = el.ownerDocument;
-    let env = doc.createElement("iframe");
+    let env = el.ownerDocument.createElement("iframe");
     env.flex = 1;
 
     if (cm)
       throw new Error("You can append an editor only once.");
 
     let onLoad = () => {
       // Once the iframe is loaded, we can inject CodeMirror
       // and its dependencies into its DOM.
@@ -218,29 +217,29 @@ Editor.prototype = {
 
       // Create a CodeMirror instance add support for context menus,
       // overwrite the default controller (otherwise items in the top and
       // context menus won't work).
 
       cm = win.CodeMirror(win.document.body, this.config);
       cm.getWrapperElement().addEventListener("contextmenu", (ev) => {
         ev.preventDefault();
-        this.showContextMenu(doc, ev.screenX, ev.screenY);
+        this.showContextMenu(el.ownerDocument, ev.screenX, ev.screenY);
       }, false);
 
       cm.on("focus", () => this.emit("focus"));
       cm.on("change", () => this.emit("change"));
       cm.on("gutterClick", (cm, line) => this.emit("gutterClick", line));
       cm.on("cursorActivity", (cm) => this.emit("cursorActivity"));
 
       win.CodeMirror.defineExtension("l10n", (name) => {
         return L10N.GetStringFromName(name);
       });
 
-      doc.defaultView.controllers.insertControllerAt(0, controller(this, doc.defaultView));
+      cm.getInputField().controllers.insertControllerAt(0, controller(this));
 
       this.container = env;
       editors.set(this, cm);
       def.resolve();
     };
 
     env.addEventListener("load", onLoad, true);
     env.setAttribute("src", CM_IFRAME);
@@ -698,28 +697,26 @@ function getCSSKeywords() {
   };
 }
 
 /**
  * Returns a controller object that can be used for
  * editor-specific commands such as find, jump to line,
  * copy/paste, etc.
  */
-function controller(ed, view) {
+function controller(ed) {
   return {
     supportsCommand: function (cmd) {
       switch (cmd) {
         case "cmd_find":
         case "cmd_findAgain":
         case "cmd_findPrevious":
         case "cmd_gotoLine":
         case "cmd_undo":
         case "cmd_redo":
-        case "cmd_cut":
-        case "cmd_paste":
         case "cmd_delete":
         case "cmd_selectAll":
           return true;
       }
 
       return false;
     },
 
@@ -732,22 +729,18 @@ function controller(ed, view) {
         case "cmd_selectAll":
           return true;
         case "cmd_findAgain":
           return cm.state.search != null && cm.state.search.query != null;
         case "cmd_undo":
           return ed.canUndo();
         case "cmd_redo":
           return ed.canRedo();
-        case "cmd_cut":
-          return cm.getOption("readOnly") !== true && ed.somethingSelected();
         case "cmd_delete":
           return ed.somethingSelected();
-        case "cmd_paste":
-          return cm.getOption("readOnly") !== true;
       }
 
       return false;
     },
 
     doCommand: function (cmd) {
       let cm  = editors.get(ed);
       let map = {
@@ -757,22 +750,16 @@ function controller(ed, view) {
         "cmd_redo": "redo",
         "cmd_delete": "delCharAfter",
         "cmd_findAgain": "findNext"
       };
 
       if (map[cmd])
         return void cm.execCommand(map[cmd]);
 
-      if (cmd === "cmd_cut")
-        return void view.goDoCommand("cmd_cut");
-
-      if (cmd === "cmdste")
-        return void view.goDoCommand("cmd_paste");
-
       if (cmd == "cmd_gotoLine")
         ed.jumpToLine(cm);
     },
 
     onEvent: function () {}
   };
 }