X-Git-Url: https://git.donarmstrong.com/?p=dactyl.git;a=blobdiff_plain;f=common%2Fmodules%2Fcompletion.jsm;h=24b091a0d935631a47b3c74442b226eb44afa453;hp=eec3857bbf914d584154414053c8e10838e94fd1;hb=3d837eb266a3a01d424192aa4ec1a167366178c5;hpb=d8a3bcebff36df7b128b36e0b57b715479e155a0 diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index eec3857..24b091a 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -135,10 +135,10 @@ var CompletionContext = Class("CompletionContext", { * {@link #filters} array. */ this.filterFunc = function filterFunc(items) { - let self = this; - return this.filters. - reduce(function r(res, filter) res.filter(function f(item) filter.call(self, item)), - items); + return this.filters + .reduce((res, filter) + => res.filter((item) => filter.call(this, item)), + items); }; /** * @property {Array} An array of predicates on which to filter the @@ -674,7 +674,6 @@ var CompletionContext = Class("CompletionContext", { }, getRows: function getRows(start, end, doc) { - let self = this; let items = this.items; let cache = this.cache.rows; let step = start > end ? -1 : 1; @@ -706,8 +705,8 @@ var CompletionContext = Class("CompletionContext", { * for the new context. If a string is provided, it is * interpreted as a method to access on *self*. */ - fork: function fork(name, offset, self, completer) { - return this.forkapply(name, offset, self, completer, Array.slice(arguments, fork.length)); + fork: function fork(name, offset, self, completer, ...args) { + return this.forkapply(name, offset, self, completer, args); }, forkapply: function forkapply(name, offset, self, completer, args) { @@ -732,13 +731,11 @@ var CompletionContext = Class("CompletionContext", { return context; }, - split: function split(name, obj, fn) { - const self = this; - + split: function split(name, obj, fn, ...args) { let context = this.fork(name); - function alias(prop) { - context.__defineGetter__(prop, function get_() self[prop]); - context.__defineSetter__(prop, function set_(val) self[prop] = val); + let alias = (prop) => { + context.__defineGetter__(prop, () => this[prop]); + context.__defineSetter__(prop, (val) => this[prop] = val); } alias("_cache"); alias("_completions"); @@ -749,7 +746,7 @@ var CompletionContext = Class("CompletionContext", { context.hasItems = true; this.hasItems = false; if (fn) - return fn.apply(obj || this, [context].concat(Array.slice(arguments, split.length))); + return fn.apply(obj || this, [context].concat(args)); return context; }, @@ -821,7 +818,6 @@ var CompletionContext = Class("CompletionContext", { * context. */ reset: function reset() { - let self = this; if (this.parent) throw Error(); @@ -842,7 +838,7 @@ var CompletionContext = Class("CompletionContext", { this.value = this._value; this._caret = this.value.length; } - //for (let key in (k for ([k, v] in Iterator(self.contexts)) if (v.offset > this.caret))) + //for (let key in (k for ([k, v] in Iterator(this.contexts)) if (v.offset > this.caret))) // delete this.contexts[key]; for each (let context in this.contexts) { context.hasItems = false; @@ -907,10 +903,10 @@ var Completion = Module("completion", { get options() modules.options, // FIXME - _runCompleter: function _runCompleter(name, filter, maxItems) { + _runCompleter: function _runCompleter(name, filter, maxItems, ...args) { let context = modules.CompletionContext(filter); context.maxItems = maxItems; - let res = context.fork.apply(context, ["run", 0, this, name].concat(Array.slice(arguments, 3))); + let res = context.fork.apply(context, ["run", 0, this, name].concat(args)); if (res) { if (Components.stack.caller.name === "runCompleter") // FIXME return { items: res.map(function m(i) ({ item: i })) }; @@ -921,14 +917,14 @@ var Completion = Module("completion", { }, runCompleter: function runCompleter(name, filter, maxItems) { - return this._runCompleter.apply(this, Array.slice(arguments)) + return this._runCompleter.apply(this, arguments) .items.map(function m(i) i.item); }, - listCompleter: function listCompleter(name, filter, maxItems) { + listCompleter: function listCompleter(name, filter, maxItems, ...args) { let context = modules.CompletionContext(filter || ""); context.maxItems = maxItems; - context.fork.apply(context, ["list", 0, this, name].concat(Array.slice(arguments, 3))); + context.fork.apply(context, ["list", 0, this, name].concat(args)); context = context.contexts["/list"]; context.wait(null, true); @@ -943,7 +939,7 @@ var Completion = Module("completion", { template.map(contexts, function m(context) [template.completionRow(context.title, "CompTitle"), template.map(context.items, function m(item) context.createRow(item), null, 100)])]); - }, + } }), //////////////////////////////////////////////////////////////////////////////// @@ -991,10 +987,10 @@ var Completion = Module("completion", { }, this); }, - addUrlCompleter: function addUrlCompleter(opt) { - let completer = Completion.UrlCompleter.apply(null, Array.slice(arguments)); - completer.args = Array.slice(arguments, completer.length); - this.urlCompleters[opt] = completer; + addUrlCompleter: function addUrlCompleter(name, description, completer, ...args) { + let completer = Completion.UrlCompleter(name, description, completer); + completer.args = args; + this.urlCompleters[name] = completer; }, autocomplete: curry(function autocomplete(provider, context) { @@ -1019,7 +1015,7 @@ var Completion = Module("completion", { let words = context.filter.toLowerCase().split(/\s+/g); context.hasItems = true; context.completions = context.completions.filter(function f({ url, title }) - words.every(function e(w) (url + " " + title).toLowerCase().indexOf(w) >= 0)) + words.every(function e(w) (url + " " + title).toLowerCase().indexOf(w) >= 0)); context.format = this.modules.bookmarks.format; context.keys.extra = function k_extra(item) { @@ -1229,4 +1225,4 @@ endModule(); // catch(e){ if (!e.stack) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); } -// vim: set fdm=marker sw=4 ts=4 et ft=javascript: +// vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: