1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 16:12:26 +01:00

Remove ridiculously tortuous mappings code (again).

This commit is contained in:
Kris Maglione
2008-11-28 05:58:58 +00:00
parent 9bbab5ab22
commit 20596df015
2 changed files with 21 additions and 49 deletions

View File

@@ -136,6 +136,7 @@ function Mappings() //{{{
function expandLeader(keyString) keyString.replace(/<Leader>/i, mappings.getMapLeader()) function expandLeader(keyString) keyString.replace(/<Leader>/i, mappings.getMapLeader())
// Return all mappings present in all @modes
function mappingsIterator(modes, stack) function mappingsIterator(modes, stack)
{ {
modes = modes.slice(); modes = modes.slice();
@@ -302,10 +303,10 @@ function Mappings() //{{{
var map = new Map(modes, keys, description || "User defined mapping", action, extra); var map = new Map(modes, keys, description || "User defined mapping", action, extra);
// remove all old mappings to this key sequence // remove all old mappings to this key sequence
for (let i = 0; i < map.names.length; i++) for (let [,name] in Iterator(map.names))
{ {
for (let j = 0; j < map.modes.length; j++) for (let [,mode] in Iterator(map.modes))
removeMap(map.modes[j], map.names[i]); removeMap(mode, map.name);
} }
addMap(map, true); addMap(map, true);
@@ -369,47 +370,7 @@ function Mappings() //{{{
list: function (modes, filter) list: function (modes, filter)
{ {
// modes means, a map must exist in both modes in order to get listed let modeSign = "";
var maps = user[modes[0]]; // duplicate (reference) (first mode where it must match)
var output = [];
if (!maps || maps.length == 0)
{
liberator.echo("No mappings found");
return;
}
for (let [i, map] in Iterator(maps)) // check on maps items (first mode)
{
output[i] = !filter || map.names[0] == filter;
if (!output[i]) // does it match the filter first of all?
continue;
for (let [, mode] in Iterator(modes))
{
output[i] = false; // toggle false, only true whan also found in this mode
for (let [, usermode] in Iterator(user[mode]))
{
// NOTE: when other than user maps, there might be more than only one names[x].
// since only user mappings gets queried here, only names[0] gets checked for equality.
if (map.rhs == usermode.rhs && map.names[0] == usermode.names[0])
{
output[i] = true;
break; // found on this mode - ok, check next mode...
}
}
break; // not found in this mode -> map wont' match all modes...
}
}
// anything found?
var flag = output.some(util.identity);
if (!flag)
{
liberator.echo("No mappings found");
return;
}
var modeSign = "";
modes.forEach(function (mode) modes.forEach(function (mode)
{ {
if (mode == modes.NORMAL) if (mode == modes.NORMAL)
@@ -422,11 +383,13 @@ function Mappings() //{{{
modeSign += "m"; modeSign += "m";
}); });
let _maps = (map for ([i, map] in Iterator(maps)) let maps = mappingsIterator(modes, user);
if (output[i])); if (filter)
maps = (map for (map in maps) if (map.names[0] == filter));
let list = <table> let list = <table>
{ {
template.map(_maps, function (map) template.map(maps, function (map)
template.map(map.names, function (name) template.map(map.names, function (name)
<tr> <tr>
<td>{modeSign} {name}</td> <td>{modeSign} {name}</td>
@@ -435,6 +398,13 @@ function Mappings() //{{{
</tr>)) </tr>))
} }
</table>; </table>;
// TODO: Move this to an ItemList to show this automatically
if (list.*.length() == list.text().length())
{
liberator.echo(<div highlight="Title">No mappings found</div>, commandline.FORCE_MULTILINE);
return;
}
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
} }

View File

@@ -692,7 +692,9 @@ function Options() //{{{
let scope = modifiers && modifiers.scope || options.OPTION_SCOPE_BOTH; let scope = modifiers && modifiers.scope || options.OPTION_SCOPE_BOTH;
let opts = (opt for (opt in options) let opts = (opt for (opt in options)
if ((opt.scope & scope) && (!prefix || opt.type == "boolean" || prefix == "inv" && /list$/.test(opt.type)))); if ((opt.scope & scope) &&
(!prefix || opt.type == "boolean" ||
prefix == "inv" && opt.value instanceof Array)));
if (filter.indexOf("=") == -1) if (filter.indexOf("=") == -1)
{ {
@@ -750,7 +752,7 @@ function Options() //{{{
if (!res) if (!res)
return; return;
completions = completions.concat(res); completions = completions.concat(res);
if (/list$/.test(option.type)) if (option.values instanceof Array)
{ {
completions = completions.filter(function (val) opt.values.indexOf(val[0]) == -1); completions = completions.filter(function (val) opt.values.indexOf(val[0]) == -1);
switch (opt.operator) switch (opt.operator)