mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 05:27:58 +01:00
add support for arbitrary {rhs} key sequences and <Leader> to :noremap
This commit is contained in:
@@ -1202,11 +1202,10 @@ vimperator.Commands = function() //{{{
|
|||||||
function(args) { vimperator.editor.removeAllAbbreviations("i"); },
|
function(args) { vimperator.editor.removeAllAbbreviations("i"); },
|
||||||
{ short_help: "Remove all abbreviations for Insert mode" }
|
{ short_help: "Remove all abbreviations for Insert mode" }
|
||||||
));
|
));
|
||||||
addDefaultCommand(new vimperator.Command(["map"],
|
|
||||||
// 0 args -> list all maps
|
// 0 args -> list all maps
|
||||||
// 1 arg -> list the maps starting with args
|
// 1 arg -> list the maps starting with args
|
||||||
// 2 args -> map arg1 to arg*
|
// 2 args -> map arg1 to arg*
|
||||||
function(args)
|
function map(args, noremap)
|
||||||
{
|
{
|
||||||
if (!args)
|
if (!args)
|
||||||
{
|
{
|
||||||
@@ -1229,7 +1228,7 @@ vimperator.Commands = function() //{{{
|
|||||||
if (rhs)
|
if (rhs)
|
||||||
{
|
{
|
||||||
vimperator.mappings.add(new vimperator.Map([vimperator.modes.NORMAL], [lhs],
|
vimperator.mappings.add(new vimperator.Map([vimperator.modes.NORMAL], [lhs],
|
||||||
function(count) { vimperator.events.feedkeys((count > 1 ? count : "") + rhs); },
|
function(count) { vimperator.events.feedkeys((count > 1 ? count : "") + rhs, noremap); },
|
||||||
{ flags: vimperator.Mappings.flags.COUNT, rhs: rhs }
|
{ flags: vimperator.Mappings.flags.COUNT, rhs: rhs }
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -1238,7 +1237,9 @@ vimperator.Commands = function() //{{{
|
|||||||
// FIXME: no filtering for now
|
// FIXME: no filtering for now
|
||||||
vimperator.mappings.list(vimperator.modes.NORMAL, lhs);
|
vimperator.mappings.list(vimperator.modes.NORMAL, lhs);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
addDefaultCommand(new vimperator.Command(["map"],
|
||||||
|
function(args) { map(args, false) },
|
||||||
{
|
{
|
||||||
usage: ["map {lhs} {rhs}", "map {lhs}", "map"],
|
usage: ["map {lhs} {rhs}", "map {lhs}", "map"],
|
||||||
short_help: "Map the key sequence {lhs} to {rhs}",
|
short_help: "Map the key sequence {lhs} to {rhs}",
|
||||||
@@ -1397,56 +1398,12 @@ vimperator.Commands = function() //{{{
|
|||||||
));
|
));
|
||||||
// TODO: remove duplication in :map
|
// TODO: remove duplication in :map
|
||||||
addDefaultCommand(new vimperator.Command(["no[remap]"],
|
addDefaultCommand(new vimperator.Command(["no[remap]"],
|
||||||
// 0 args -> list all maps
|
function(args) { map(args, true) },
|
||||||
// 1 arg -> list the maps starting with args
|
|
||||||
// 2 args -> map arg1 to arg*
|
|
||||||
function(args)
|
|
||||||
{
|
|
||||||
if (!args)
|
|
||||||
{
|
|
||||||
vimperator.mappings.list(vimperator.modes.NORMAL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var matches = args.match(/^([^ ]+)(?:\s+(.+))?$/);
|
|
||||||
var [lhs, rhs] = [matches[1], matches[2]];
|
|
||||||
|
|
||||||
if (rhs)
|
|
||||||
{
|
|
||||||
if (/^:/.test(rhs))
|
|
||||||
{
|
|
||||||
vimperator.mappings.add(
|
|
||||||
new vimperator.Map([vimperator.modes.NORMAL], [lhs], function() { vimperator.execute(rhs); }, { rhs: rhs })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NOTE: we currently only allow one normal mode command in {rhs}
|
|
||||||
var map = vimperator.mappings.getDefaultMap(vimperator.modes.NORMAL, rhs);
|
|
||||||
|
|
||||||
// create a new Map for {lhs} with the same action as
|
|
||||||
// {rhs}...until we have feedkeys().
|
|
||||||
// NOTE: Currently only really intended for static use (e.g.
|
|
||||||
// from the RC file) since {rhs} is evaluated when the map
|
|
||||||
// is created not at runtime
|
|
||||||
if (map)
|
|
||||||
vimperator.mappings.add(
|
|
||||||
new vimperator.Map([vimperator.modes.NORMAL], [lhs], map.action, { flags: map.flags, rhs: rhs })
|
|
||||||
);
|
|
||||||
else
|
|
||||||
vimperator.echoerr("E475: Invalid argument: " + "{rhs} must be a existing singular mapping");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// FIXME: no filtering for now
|
|
||||||
vimperator.mappings.list(vimperator.modes.NORMAL, lhs);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
usage: ["no[remap] {lhs} {rhs}", "no[remap] {lhs}", "no[remap]"],
|
usage: ["no[remap] {lhs} {rhs}", "no[remap] {lhs}", "no[remap]"],
|
||||||
short_help: "Map the key sequence {lhs} to {rhs}",
|
short_help: "Map the key sequence {lhs} to {rhs}",
|
||||||
help: "No remapping of the <code class=\"argument\">{rhs}</code> is performed.<br/>NOTE: :noremap does not yet work as reliably as :map."
|
help: "No remapping of the <code class=\"argument\">{rhs}</code> is performed.<br/>" +
|
||||||
|
"NOTE: :noremap does not yet work as reliably as :map."
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
addDefaultCommand(new vimperator.Command(["o[pen]", "e[dit]"],
|
addDefaultCommand(new vimperator.Command(["o[pen]", "e[dit]"],
|
||||||
|
|||||||
@@ -268,12 +268,14 @@ vimperator.Events = function() //{{{
|
|||||||
//
|
//
|
||||||
// @param keys: a string like "2<C-f>" to pass
|
// @param keys: a string like "2<C-f>" to pass
|
||||||
// if you want < to be taken literally, prepend it with a \\
|
// if you want < to be taken literally, prepend it with a \\
|
||||||
this.feedkeys = function(keys)
|
this.feedkeys = function(keys, noremap)
|
||||||
{
|
{
|
||||||
var doc = window.document;
|
var doc = window.document;
|
||||||
var view = window.document.defaultView;
|
var view = window.document.defaultView;
|
||||||
var escapeKey = false; // \ to escape some special keys
|
var escapeKey = false; // \ to escape some special keys
|
||||||
|
|
||||||
|
noremap = !!noremap;
|
||||||
|
|
||||||
for (var i = 0; i < keys.length; i++)
|
for (var i = 0; i < keys.length; i++)
|
||||||
{
|
{
|
||||||
var charCode = keys.charCodeAt(i);
|
var charCode = keys.charCodeAt(i);
|
||||||
@@ -306,8 +308,10 @@ vimperator.Events = function() //{{{
|
|||||||
{
|
{
|
||||||
charCode = 0;
|
charCode = 0;
|
||||||
}
|
}
|
||||||
else //an invalid key like <A-xxx> was found, stop propagation here (like vim)
|
else //an invalid key like <A-xxx> was found, stop propagation here (like Vim)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
i += matches[0].length + 1;
|
i += matches[0].length + 1;
|
||||||
}
|
}
|
||||||
@@ -319,6 +323,7 @@ vimperator.Events = function() //{{{
|
|||||||
|
|
||||||
var evt = doc.createEvent("KeyEvents");
|
var evt = doc.createEvent("KeyEvents");
|
||||||
evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
|
evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
|
||||||
|
evt.noremap = noremap;
|
||||||
elem.dispatchEvent(evt);
|
elem.dispatchEvent(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -636,6 +641,10 @@ vimperator.Events = function() //{{{
|
|||||||
var count_str = vimperator.input.buffer.match(/^[0-9]*/)[0];
|
var count_str = vimperator.input.buffer.match(/^[0-9]*/)[0];
|
||||||
var candidate_command = (vimperator.input.buffer + key).replace(count_str, "");
|
var candidate_command = (vimperator.input.buffer + key).replace(count_str, "");
|
||||||
var map;
|
var map;
|
||||||
|
if (event.noremap)
|
||||||
|
map = vimperator.mappings.getDefaultMap(vimperator.mode, candidate_command);
|
||||||
|
else
|
||||||
|
map = vimperator.mappings.get(vimperator.mode, candidate_command);
|
||||||
|
|
||||||
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
|
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
|
||||||
if ((vimperator.input.buffer + key).match(/^[1-9][0-9]*$/))
|
if ((vimperator.input.buffer + key).match(/^[1-9][0-9]*$/))
|
||||||
@@ -655,7 +664,7 @@ vimperator.Events = function() //{{{
|
|||||||
|
|
||||||
vimperator.input.pendingArgMap = null;
|
vimperator.input.pendingArgMap = null;
|
||||||
}
|
}
|
||||||
else if (map = vimperator.mappings.get(vimperator.mode, candidate_command))
|
else if (map)
|
||||||
{
|
{
|
||||||
vimperator.input.count = parseInt(count_str, 10);
|
vimperator.input.count = parseInt(count_str, 10);
|
||||||
if (isNaN(vimperator.input.count))
|
if (isNaN(vimperator.input.count))
|
||||||
|
|||||||
Reference in New Issue
Block a user