1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-23 09:23:33 +01:00

Use builtin String.startsWith, String.endsWith, and String.contains methods where appropriate.

This commit is contained in:
Kris Maglione
2014-02-22 15:17:08 -08:00
parent 6790c62c41
commit 51eb03c376
19 changed files with 40 additions and 39 deletions

View File

@@ -267,7 +267,7 @@ var Abbreviations = Module("abbreviations", {
let hives = (hives || this.userHives).filter(h => !h.empty);
function abbrevs(hive)
hive.merged.filter(ab => (ab.inModes(modes) && ab.lhs.indexOf(lhs) == 0));
hive.merged.filter(ab => (ab.inModes(modes) && ab.lhs.startsWith(lhs)));
let list = ["table", {},
["tr", { highlight: "Title" },

View File

@@ -656,7 +656,7 @@ var Bookmarks = Module("bookmarks", {
keyword, true);
let item = keywords[keyword];
if (item && item.url.indexOf("%s") > -1)
if (item && item.url.contains("%s"))
context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) {
context.format = history.format;
context.title = [/*L*/keyword + " Quick Search"];
@@ -669,7 +669,7 @@ var Bookmarks = Module("bookmarks", {
return history.get({ uri: util.newURI(begin), uriIsPrefix: true }).map(function (item) {
let rest = item.url.length - end.length;
let query = item.url.substring(begin.length, rest);
if (item.url.substr(rest) == end && query.indexOf("&") == -1)
if (item.url.substr(rest) == end && query.contains("&"))
try {
item.url = decodeURIComponent(query.replace(/#.*/, "").replace(/\+/g, " "));
return item;
@@ -718,14 +718,14 @@ var Bookmarks = Module("bookmarks", {
return;
let words = ctxt.filter.toLowerCase().split(/\s+/g);
ctxt.completions = ctxt.completions.filter(i => words.every(w => i.toLowerCase().indexOf(w) >= 0));
ctxt.completions = ctxt.completions.filter(i => words.every(w => i.toLowerCase().contains(w)));
ctxt.hasItems = ctxt.completions.length;
ctxt.incomplete = true;
ctxt.cache.request = bookmarks.getSuggestions(name, ctxt.filter);
ctxt.cache.request.then(function (compl) {
ctxt.incomplete = false;
ctxt.completions = array.uniq(ctxt.completions.filter(c => compl.indexOf(c) >= 0)
ctxt.completions = array.uniq(ctxt.completions.filter(c => compl.contains(c))
.concat(compl), true);
}, Cu.reportError);
});

View File

@@ -136,14 +136,14 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
&& !item.hidden
&& !/rdf:http:/.test(item.getAttribute("label"))) { // FIXME
item.dactylPath = parent + item.getAttribute("label");
if (!targetPath || targetPath.indexOf(item.dactylPath) == 0)
if (!targetPath || targetPath.startsWith(item.dactylPath))
items.push(item);
}
else {
let path = parent;
if (item.localName == "menu")
path += item.getAttribute("label") + ".";
if (!targetPath || targetPath.indexOf(path) == 0)
if (!targetPath || targetPath.startsWith(path))
addChildren(item, path);
}
}
@@ -459,7 +459,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
*/
loadScript: function loadScript(uri, context) {
let prefix = "literal:" + uri + ":";
cache.flush(s => s.indexOf(prefix) == 0);
cache.flush(s => s.startsWith(prefix));
delete literal.files[uri];
JSMLoader.loadSubScript(uri, context, File.defaultEncoding);
},
@@ -1147,7 +1147,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (error instanceof FailedAssertion && error.noTrace || error.message === "Interrupted") {
let context = contexts.context;
let prefix = context ? context.file + ":" + context.line + ": " : "";
if (error.message && error.message.indexOf(prefix) !== 0 &&
if (error.message && !error.message.startsWith(prefix) &&
prefix != "[Command Line]:1: ")
error.message = prefix + error.message;

View File

@@ -764,7 +764,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
context = context.fork("registers");
context.keys = { text: util.identity, description: editor.closure.getRegister };
context.match = function (r) !this.filter || ~this.filter.indexOf(r);
context.match = function (r) !this.filter || this.filter.contains(r);
context.fork("clipboard", 0, this, function (ctxt) {
ctxt.match = context.match;

View File

@@ -695,7 +695,7 @@ var HintSession = Class("HintSession", CommandMode, {
updateValidNumbers: function updateValidNumbers(always) {
let string = this.getHintString(this.hintNumber);
for (let hint in values(this.validHints))
hint.valid = always || hint.span.getAttribute("number").indexOf(string) == 0;
hint.valid = always || hint.span.getAttribute("number").startsWith(string);
},
tab: function tab(previous) {
@@ -1071,7 +1071,7 @@ var Hints = Module("hints", {
mappings.popCommand();
},
onChange: function (arg) {
if (Object.keys(hints.modes).some(m => m != arg && m.indexOf(arg) == 0))
if (Object.keys(hints.modes).some(m => m != arg && m.startsWith(arg)))
return;
this.accepted = true;

View File

@@ -714,6 +714,7 @@ var Mappings = Module("mappings", {
function uniqueModes(modes) {
let chars = [k for ([k, v] in Iterator(modules.modes.modeChars))
if (v.every(mode => modes.indexOf(mode) >= 0))];
return array.uniq(modes.filter(m => chars.indexOf(m.char) < 0)
.map(m => m.name.toLowerCase())
.concat(chars));