]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/content/commandline.js
Import r6948 from upstream hg supporting Firefox up to 24.*
[dactyl.git] / common / content / commandline.js
index f01cbb0b33b9f31a84b8d7af8bfd8ca3c5438037..9ea1fc33ba78d13920b7979c8f0430e5fee2756b 100644 (file)
@@ -54,7 +54,7 @@ var CommandWidgets = Class("CommandWidgets", {
                     ["vbox", { id: "dactyl-completions-" + s + "commandline-container", class: "dactyl-container", hidden: "false", collapsed: "true" },
                         ["iframe", { class: "dactyl-completions", id: "dactyl-completions-" + s + "commandline", src: "dactyl://content/buffer.xhtml",
                                      contextmenu: "dactyl-contextmenu", flex: "1", hidden: "false", collapsed: "false", highlight: "Events",
-                                     events: "mowEvents" }]]]],
+                                     events: "mowEvents" }]]]]
         });
 
         this.elements = {};
@@ -167,11 +167,11 @@ var CommandWidgets = Class("CommandWidgets", {
 
         function get(prefix, map, id) (obj.getElement || util.identity)(map[id] || document.getElementById(prefix + id));
 
-        this.active.__defineGetter__(obj.name, function () self.activeGroup[obj.name][obj.name]);
-        this.activeGroup.__defineGetter__(obj.name, function () self.getGroup(obj.name));
+        this.active.__defineGetter__(obj.name, () => this.activeGroup[obj.name][obj.name]);
+        this.activeGroup.__defineGetter__(obj.name, () => this.getGroup(obj.name));
 
-        memoize(this.statusbar, obj.name, function () get("dactyl-statusline-field-", statusline.widgets, (obj.id || obj.name)));
-        memoize(this.commandbar, obj.name, function () get("dactyl-", {}, (obj.id || obj.name)));
+        memoize(this.statusbar, obj.name, () => get("dactyl-statusline-field-", statusline.widgets, (obj.id || obj.name)));
+        memoize(this.commandbar, obj.name, () => get("dactyl-", {}, (obj.id || obj.name)));
 
         if (!(obj.noValue || obj.getValue)) {
             Object.defineProperty(this, obj.name, Modes.boundProperty({
@@ -488,9 +488,9 @@ var CommandPromptMode = Class("CommandPromptMode", CommandMode, {
         init.supercall(this);
     },
 
-    complete: function CPM_complete(context) {
+    complete: function CPM_complete(context, ...args) {
         if (this.completer)
-            context.forkapply("prompt", 0, this, "completer", Array.slice(arguments, 1));
+            context.forkapply("prompt", 0, this, "completer", args);
     },
 
     get mode() modes.PROMPT
@@ -504,8 +504,6 @@ var CommandPromptMode = Class("CommandPromptMode", CommandMode, {
  */
 var CommandLine = Module("commandline", {
     init: function init() {
-        const self = this;
-
         this._callbacks = {};
 
         memoize(this, "_store", function () storage.newMap("command-history", { store: true, privateData: true }));
@@ -634,7 +632,7 @@ var CommandLine = Module("commandline", {
 
             node.completionList = ItemList(elem);
             node.completionList.isAboveMow = node.id ==
-                this.widgets.statusbar.commandline.id
+                this.widgets.statusbar.commandline.id;
         }
         return node.completionList;
     },
@@ -741,7 +739,7 @@ var CommandLine = Module("commandline", {
         if (val)
             this.widgets["message-pre"] = _("commandline.moreMessages", val) + " ";
         else
-            this.widgets["message-pre"] = null
+            this.widgets["message-pre"] = null;
     },
 
     _lastEcho: null,
@@ -777,13 +775,12 @@ var CommandLine = Module("commandline", {
 
         highlightGroup = highlightGroup || this.HL_NORMAL;
 
-        let self = this;
-        function appendToMessages(data) {
+        let appendToMessages = (data) => {
             let message = isObject(data) && !DOM.isJSONXML(data) ? data : { message: data };
 
             // Make sure the memoized message property is an instance property.
             message.message;
-            self._messageHistory.add(update({ highlight: highlightGroup }, message));
+            this._messageHistory.add(update({ highlight: highlightGroup }, message));
             return message.message;
         }
 
@@ -802,7 +799,7 @@ var CommandLine = Module("commandline", {
         if ((flags & this.FORCE_MULTILINE) || (/\n/.test(data) || !isinstance(data, [_, "String"])) && !(flags & this.FORCE_SINGLELINE))
             action = mow.closure.echo;
 
-        let single = function () action == self._echoLine;
+        let checkSingleLine = () => action == this._echoLine;
 
         if (forceSingle) {
             this._lastEcho = null;
@@ -810,11 +807,11 @@ var CommandLine = Module("commandline", {
         }
         else {
             // So complicated...
-            if (single() && !this.widgets.mowContainer.collapsed) {
+            if (checkSingleLine() && !this.widgets.mowContainer.collapsed) {
                 highlightGroup += " Message";
                 action = mow.closure.echo;
             }
-            else if (!single() && this.widgets.mowContainer.collapsed) {
+            else if (!checkSingleLine() && this.widgets.mowContainer.collapsed) {
                 if (this._lastEcho && this.widgets.message && this.widgets.message[1] == this._lastEcho.msg) {
                     if (!(this._lastEcho.flags & this.APPEND_TO_MESSAGES))
                         appendToMessages(this._lastEcho.data);
@@ -832,20 +829,20 @@ var CommandLine = Module("commandline", {
             else if (this._lastEcho && this.widgets.message && this.widgets.message[1] == this._lastEcho.msg) {
                 if (!(this._lastEcho.flags & this.APPEND_TO_MESSAGES))
                     appendToMessages(this._lastEcho.data);
-                if (single() && !(flags & this.APPEND_TO_MESSAGES))
+                if (checkSingleLine() && !(flags & this.APPEND_TO_MESSAGES))
                     appendToMessages(data);
 
                 flags |= this.APPEND_TO_MESSAGES;
                 this.hiddenMessages++;
             }
-            this._lastEcho = single() && { flags: flags, msg: data, data: arguments[0] };
+            this._lastEcho = checkSingleLine() && { flags: flags, msg: data, data: arguments[0] };
         }
 
         this._lastClearable = action === this._echoLine && String(data);
         this._lastEchoTime = (flags & this.FORCE_SINGLELINE) && Date.now();
 
         if (action)
-            action.call(this, data, highlightGroup, single);
+            action.call(this, data, highlightGroup, checkSingleLine());
     },
     _lastEchoTime: 0,
 
@@ -958,7 +955,7 @@ var CommandLine = Module("commandline", {
 
     updateOutputHeight: deprecated("mow.resize", function updateOutputHeight(open, extra) mow.resize(open, extra)),
 
-    withOutputToString: function withOutputToString(fn, self) {
+    withOutputToString: function withOutputToString(fn, self, ...args) {
         dactyl.registerObserver("echoLine", observe, true);
         dactyl.registerObserver("echoMultiline", observe, true);
 
@@ -968,7 +965,7 @@ var CommandLine = Module("commandline", {
         }
 
         this.savingOutput = true;
-        dactyl.trapErrors.apply(dactyl, [fn, self].concat(Array.slice(arguments, 2)));
+        dactyl.trapErrors.apply(dactyl, [fn, self].concat(args));
         this.savingOutput = false;
         return output.map(function (elem) elem instanceof Node ? DOM.stringify(elem) : elem)
                      .join("\n");
@@ -1013,7 +1010,7 @@ var CommandLine = Module("commandline", {
 
             this.store = this.store.filter(function (line) (line.value || line) != str);
             dactyl.trapErrors(function () {
-                this.store.push({ value: str, timestamp: Date.now()*1000, privateData: privateData });
+                this.store.push({ value: str, timestamp: Date.now() * 1000, privateData: privateData });
             }, this);
             this.store = this.store.slice(Math.max(0, this.store.length - options["history"]));
         },
@@ -1767,8 +1764,7 @@ var CommandLine = Module("commandline", {
                 return Events.PASS;
             });
 
-        let bind = function bind()
-            mappings.add.apply(mappings, [[modes.COMMAND_LINE]].concat(Array.slice(arguments)))
+        let bind = function bind(...args) mappings.add.apply(mappings, [[modes.COMMAND_LINE]].concat(args));
 
         bind(["<Esc>", "<C-[>"], "Stop waiting for completions or exit Command Line mode",
              function ({ self }) {
@@ -2030,7 +2026,7 @@ var ItemList = Class("ItemList", {
         if (start < 0 || start >= this.itemCount)
             return null;
 
-        group = array.nth(groups, function (g) let (i = start - g.offsets.start) i >= 0 && i < g.itemCount, 0)
+        group = array.nth(groups, function (g) let (i = start - g.offsets.start) i >= 0 && i < g.itemCount, 0);
         return [group.context, start - group.offsets.start];
     },
 
@@ -2342,7 +2338,7 @@ var ItemList = Class("ItemList", {
                 container.scrollTop = scroll;
                 if (scrollY != null)
                     win.scrollTo(0, Math.max(scrollY, 0));
-            }
+            };
         },
 
         /**
@@ -2455,4 +2451,4 @@ var ItemList = Class("ItemList", {
     })
 });
 
-// vim: set fdm=marker sw=4 ts=4 et:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et: