Commit 710bb0f6 authored by Anton Kovalyov's avatar Anton Kovalyov
Browse files

Bug 933015 - Attach Editor controller to the hidden textarea instead of a CM window. r=benvie

parent a44a1283
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@
<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>
+4 −17
Original line number Diff line number Diff line
@@ -185,8 +185,7 @@ Editor.prototype = {
  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)
@@ -223,7 +222,7 @@ Editor.prototype = {
      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"));
@@ -235,7 +234,7 @@ Editor.prototype = {
        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);
@@ -703,7 +702,7 @@ function getCSSKeywords() {
 * 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) {
@@ -713,8 +712,6 @@ function controller(ed, view) {
        case "cmd_gotoLine":
        case "cmd_undo":
        case "cmd_redo":
        case "cmd_cut":
        case "cmd_paste":
        case "cmd_delete":
        case "cmd_selectAll":
          return true;
@@ -737,12 +734,8 @@ function controller(ed, view) {
          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;
@@ -762,12 +755,6 @@ function controller(ed, view) {
      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);
    },