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

map multi-mode enhancement, i = Insert+Textarea

This commit is contained in:
Marco Candrian
2007-12-07 04:22:41 +00:00
parent bcc3ca6dd8
commit 376cb2c6e8
2 changed files with 115 additions and 39 deletions

View File

@@ -1301,11 +1301,9 @@ vimperator.Commands = function () //{{{
// 2 args -> map arg1 to arg*
function map(args, mode, noremap)
{
for (var index = 0; index < mode.length; index++) // XXX: actually no multi-modes arrives here
if (!args)
{
if (!args) // TODO: list: function -> allow multiple modes, if once necessary
{
vimperator.mappings.list(mode[index]);
vimperator.mappings.list(mode);
return;
}
@@ -1316,18 +1314,19 @@ vimperator.Commands = function () //{{{
if (leaderRegexp.test(lhs))
lhs = lhs.replace(leaderRegexp, vimperator.events.getMapLeader());
if (rhs)
if (!rhs) // list the mapping
{
vimperator.mappings.list(mode, lhs);
}
else
{
for (var index = 0; index < mode.length; index++)
{
vimperator.mappings.add(new vimperator.Map([mode[index]], [lhs],
function (count) { vimperator.events.feedkeys((count > 1 ? count : "") + rhs, noremap); },
{ flags: vimperator.Mappings.flags.COUNT, rhs: rhs, noremap: noremap}
));
}
else
{
// FIXME: no filtering for now
vimperator.mappings.list(mode[index], lhs);
}
}
}
commandManager.add(new vimperator.Command(["map"],
@@ -1349,7 +1348,7 @@ vimperator.Commands = function () //{{{
}
));
commandManager.add(new vimperator.Command(["im[ap]"],
function (args) { map(args, [vimperator.modes.INSERT], false); },
function (args) { map(args, [vimperator.modes.INSERT, vimperator.modes.TEXTAREA], false); },
{
usage: ["imap {lhs} {rhs}", "imap {lhs}", "imap"],
shortHelp: "Map the key sequence {lhs} to {rhs} (in insert mode)",
@@ -1401,6 +1400,7 @@ vimperator.Commands = function () //{{{
}
vimperator.mappings.removeAll(vimperator.modes.INSERT);
vimperator.mappings.removeAll(vimperator.modes.TEXTAREA);
},
{
shortHelp: "Remove all mappings (in insert mode)",
@@ -1474,14 +1474,13 @@ vimperator.Commands = function () //{{{
line += "\" Mappings\n";
// TODO: write user maps for all modes when we have mode dependant map support
var mode = [[vimperator.modes.NORMAL, ""], [vimperator.modes.COMMAND_LINE, "c"], [vimperator.modes.INSERT, "i"]];
var mode = [[[vimperator.modes.NORMAL], ""], [[vimperator.modes.COMMAND_LINE], "c"],
[[vimperator.modes.INSERT, vimperator.modes.TEXTAREA], "i"]];
for (var y = 0; y < mode.length; y++)
{
// names.length is about always 1 on user maps. if not, iterate here and 'fix' getUserIterator...
for (var map in vimperator.mappings.getUserIterator(mode[y][0]))
{
for (var i = 0; i < map.names.length; i++)
line += mode[y][1] + (map.noremap ? "nore" : "") + "map " + map.names[i] + " " + map.rhs + "\n";
}
line += mode[y][1] + (map.noremap ? "nore" : "") + "map " + map.names[0] + " " + map.rhs + "\n";
}
line += "\n\" Options\n";
@@ -1567,7 +1566,7 @@ vimperator.Commands = function () //{{{
}
));
commandManager.add(new vimperator.Command(["ino[remap]"],
function (args) { map(args, [vimperator.modes.INSERT], true); },
function (args) { map(args, [vimperator.modes.INSERT, vimperator.modes.TEXTAREA], true); },
{
usage: ["ino[remap] {lhs} {rhs}", "ino[remap] {lhs}", "ino[remap]"],
shortHelp: "Map the key sequence {lhs} to {rhs} (in insert mode)",
@@ -2425,10 +2424,19 @@ vimperator.Commands = function () //{{{
}
var lhs = args;
var flag = false;
if (vimperator.mappings.hasMap(vimperator.modes.INSERT, lhs))
{
vimperator.mappings.remove(vimperator.modes.INSERT, lhs);
else
flag = true;
}
if (vimperator.mappings.hasMap(vimperator.modes.TEXTAREA, lhs))
{
vimperator.mappings.remove(vimperator.modes.TEXTAREA, lhs);
flag = true;
}
if (!flag)
vimperator.echoerr("E31: No such mapping");
},
{

View File

@@ -148,13 +148,30 @@ vimperator.Mappings = function () //{{{
}
}
function mappingsIterator(mode, stack)
function mappingsIterator(modes, stack)
{
var mappings = stack[mode];
for (var i = 0; i < mappings.length; i++)
yield mappings[i];
var output;
var maps = stack[modes[0]];
for (var i = 0; i < maps.length; i++)
{
output = true;
for (var index = 1; index < modes.length; index++) // check other modes
{
output = false; // toggle false, only true whan also found in this mode
for (var z = 0; z < user[modes[index]].length; z++) // maps
{
// FIXME: when other than user maps, there might be more than one names[]? Not used so far it seems...
if (maps[i].rhs == user[modes[index]][z].rhs && maps[i].names[0] == user[modes[index]][z].names[0])
{
output = true;
break; // found on this mode - check next mode, if there is one, where it could still fail...
}
}
}
if (output)
yield maps[i];
}
throw StopIteration;
}
@@ -253,9 +270,11 @@ vimperator.Mappings = function () //{{{
return matches;
},
list: function (mode, filter)
list: function (modes, filter)
{
var maps = user[mode];
var maps = user[modes[0]]; // duplicate (reference)
var output = [];
if (!maps || maps.length == 0)
{
@@ -263,15 +282,64 @@ vimperator.Mappings = function () //{{{
return;
}
var list = "<table>";
for (var i = 0; i < maps.length; i++)
for (var i = 0; i < maps.length; i++) // check on maps items (first mode)
{
output.push(true);
if (filter && maps[i].names[0] != filter) // XXX: may compare <C-... stuff lowercase?
{
output[output.length - 1] = false;
continue;
}
for (var index = 1; index < modes.length; index++) // modes
{
output[output.length - 1] = false; // toggle false, only true whan also found in this mode
for (var z = 0; z < user[modes[index]].length; z++) // maps
{
// XXX: on user maps, names.length is always 1? (per mode, and names = user-keybinding or so)
if (maps[i].rhs == user[modes[index]][z].rhs && maps[i].names[0] == user[modes[index]][z].names[0])
{
output[output.length - 1] = true;
break; // found on this mode - ok, check next mode...
}
}
}
}
// anything found?
var flag = false;
for (var i = 0; i < output.length; i++)
if (output[i])
flag = true;
if (!flag)
{
vimperator.echo("No mappings found");
return;
}
var modeSign = "";
for (var i = 0; i < modes.length; i++)
{
if (modes[i] == vimperator.modes.NORMAL)
modeSign += 'n';
if ((modes[i] == vimperator.modes.INSERT || modes[i] == vimperator.modes.TEXTAREA) && modeSign.indexOf("i") == -1)
modeSign += 'i';
if (modes[i] == vimperator.modes.COMMAND_LINE)
modeSign += 'c';
}
var list = "<table>";
for (i = 0; i < maps.length; i++)
{
if (!output[i])
continue;
for (var j = 0; j < maps[i].names.length; j++)
{
list += "<tr>";
list += "<td> " + vimperator.util.escapeHTML(maps[i].names[j]) + "</td>";
list += "<td> " + modeSign + " " + vimperator.util.escapeHTML(maps[i].names[j]) + "</td>";
if (maps[i].rhs)
list += "<td> " + (maps[i].noremap ? "*" : " ") + "</td>" + "<td>" + vimperator.util.escapeHTML(maps[i].rhs) + "</td>";
list += "<td> "+ (maps[i].noremap ? "*" : " ") + "</td>"
+ "<td>" + vimperator.util.escapeHTML(maps[i].rhs) + "</td>";
list += "</tr>";
}
}