X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fcompletion.jsm;fp=common%2Fmodules%2Fcompletion.jsm;h=7d2b6c11da5777f10acaa8be551ee9563c682648;hb=247daf849abc85f4cfb10fa358c62c8daf8db95b;hp=001b267b7d1d84f0b63b5322c9eed5a6eab9362c;hpb=354a049cce8415487552ce405cce167b7071fe1f;p=dactyl.git diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 001b267..7d2b6c1 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -1,6 +1,6 @@ // Copyright (c) 2006-2008 by Martin Stubenschrott // Copyright (c) 2007-2011 by Doug Kearns -// Copyright (c) 2008-2013 Kris Maglione +// Copyright (c) 2008-2014 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. @@ -33,7 +33,7 @@ lazyRequire("template", ["template"]); * @constructor */ var CompletionContext = Class("CompletionContext", { - init: function cc_init(editor, name = "", offset = 0) { + init: function cc_init(editor, name="", offset=0) { let self = this; if (editor instanceof this.constructor) { let parent = editor; @@ -512,7 +512,7 @@ var CompletionContext = Class("CompletionContext", { filtered.sort(this.compare); if (!this.anchored) { let filter = this.filter; - filtered.sort(function s(a, b) (b.text.indexOf(filter) == 0) - (a.text.indexOf(filter) == 0)); + filtered.sort(function s(a, b) b.text.startsWith(filter) - a.text.startsWith(filter)); } } @@ -549,7 +549,7 @@ var CompletionContext = Class("CompletionContext", { var substrings = [text]; } else { - var compare = function compare(text, s) text.indexOf(s) >= 0; + var compare = function compare(text, s) text.contains(s); var substrings = []; let start = 0; let idx; @@ -733,7 +733,7 @@ var CompletionContext = Class("CompletionContext", { let alias = (prop) => { context.__defineGetter__(prop, () => this[prop]); context.__defineSetter__(prop, (val) => this[prop] = val); - } + }; alias("_cache"); alias("_completions"); alias("_generate"); @@ -843,7 +843,7 @@ var CompletionContext = Class("CompletionContext", { } this.waitingForTab = false; this.runCount++; - for each (let context in this.contextList) + for (let context of this.contextList) context.lastActivated = this.runCount; this.contextList = []; }, @@ -970,7 +970,7 @@ var Completion = Module("completion", { context.generate = function generate_() { return [[k.substr(services.ABOUT.length), ""] for (k in Cc) - if (k.indexOf(services.ABOUT) == 0)]; + if (k.startsWith(services.ABOUT))]; }; }); @@ -1056,7 +1056,7 @@ var Completion = Module("completion", { let contains = String.indexOf; if (context.ignoreCase) { compare = util.compareIgnoreCase; - contains = function contains_(a, b) a && a.toLowerCase().indexOf(b.toLowerCase()) > -1; + contains = function contains_(a, b) a && a.toLowerCase().contains(b.toLowerCase()); } if (tags) @@ -1180,12 +1180,13 @@ var Completion = Module("completion", { .concat([let (name = k.substr(services.AUTOCOMPLETE.length)) ["native:" + name, _("autocomplete.description", name)] for (k in Cc) - if (k.indexOf(services.AUTOCOMPLETE) == 0)]), + if (k.startsWith(services.AUTOCOMPLETE))]), setter: function setter(values) { - if (values.length == 1 && !Set.has(values[0], this.values) - && Array.every(values[0], Set.has(this.valueMap))) - return Array.map(values[0], function m(v) this[v], this.valueMap); + if (values.length == 1 && !hasOwnProperty(values[0], this.values) + && Array.every(values[0], v => hasOwnProperty(this.valueMap, v))) + return Array.map(values[0], v => this.valueMap[v]); + return values; },