mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 17:12:28 +01:00
simplify Command#hasName
This commit is contained in:
@@ -128,34 +128,18 @@ Command.prototype = {
|
|||||||
exec(args);
|
exec(args);
|
||||||
},
|
},
|
||||||
|
|
||||||
// return true if the candidate name matches one of the command's aliases
|
|
||||||
// (including all acceptable abbreviations)
|
|
||||||
hasName: function (name)
|
hasName: function (name)
|
||||||
{
|
{
|
||||||
// match a candidate name against a command name abbreviation spec - returning
|
for (let [,spec] in Iterator(this.specs))
|
||||||
// true if the candidate matches unambiguously
|
|
||||||
function matchAbbreviation(name, format)
|
|
||||||
{
|
{
|
||||||
var minimum = format.indexOf("["); // minumum number of characters for a command name match
|
let fullName = spec.replace(/\[(\w+)]$/, "$1");
|
||||||
var fullname = format.replace(/\[(\w+)\]$/, "$1"); // full command name
|
let index = spec.indexOf("[");
|
||||||
if (fullname.indexOf(name) == 0 && name.length >= minimum)
|
let min = index == -1 ? fullName.length : index;
|
||||||
|
|
||||||
|
if (fullName.indexOf(name) == 0 && name.length >= min)
|
||||||
return true;
|
return true;
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this.specs.length; i++)
|
|
||||||
{
|
|
||||||
if (this.specs[i] == name) // literal command name
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (/^(\w+|!)\[\w+\]$/.test(this.specs[i])) // abbreviation spec
|
|
||||||
{
|
|
||||||
if (matchAbbreviation(name, this.specs[i]))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user