1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-20 07:35:45 +01:00

allow multi-character normal mode user mappings

This commit is contained in:
Doug Kearns
2007-06-30 10:37:48 +00:00
parent bb23387703
commit 6f37afec74

View File

@@ -29,6 +29,7 @@ function Map(mode, cmds, act, extra_info) //{{{
} }
} }
// Since we will add many Map-objects, we add some functions as prototypes // Since we will add many Map-objects, we add some functions as prototypes
// this will ensure we only have one copy of each function, not one for each object // this will ensure we only have one copy of each function, not one for each object
Map.prototype.execute = function(motion, count, argument) Map.prototype.execute = function(motion, count, argument)
@@ -60,6 +61,7 @@ function Mappings() //{{{
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
var main = []; // array of default Map() objects var main = []; // array of default Map() objects
var user = []; // array of objects created by :map var user = []; // array of objects created by :map
@@ -89,7 +91,7 @@ function Mappings() //{{{
{ {
var mappings; var mappings;
// FIXME: initialize empty map tables -- djk // FIXME: initialize empty map tables
if (user[mode]) if (user[mode])
mappings = user[mode].concat(main[mode]) mappings = user[mode].concat(main[mode])
else else
@@ -111,13 +113,12 @@ function Mappings() //{{{
ARGUMENT: 1 << 2 ARGUMENT: 1 << 2
}; };
// NOTE: just the main/default map for now -- djk // NOTE: just normal mode for now
this.__iterator__ = function() this.__iterator__ = function()
{ {
return mappingsIterator(vimperator.modes.NORMAL); return mappingsIterator(vimperator.modes.NORMAL);
} }
// TODO: remove duplication in addDefaultMap -- djk
this.add = function(map) this.add = function(map)
{ {
if (!map) if (!map)
@@ -127,6 +128,7 @@ function Mappings() //{{{
user[map.mode] = []; user[map.mode] = [];
user[map.mode].push(map); user[map.mode].push(map);
return true; return true;
} }
@@ -153,31 +155,37 @@ function Mappings() //{{{
return map; return map;
} }
// same as this.get() but always returns an array of commands which start with "cmd" // returns an array of mappings with names which start with "cmd"
this.getCandidates = function(mode, cmd) this.getCandidates = function(mode, cmd)
{ {
var matching = []; var mappings = [];
var matches = [];
if (!mode || !cmd) if (!mode || !cmd)
return matching; return matches;
// fill matching array with maps which have commands starting with cmd if (user[mode])
for (var i = 0; i < main[mode].length; i++) // FIXME: just the main/default map space for now -- djk mappings = user[mode].concat(main[mode]);
else
mappings = main[mode];
for (var i = 0; i < mappings.length; i++)
{ {
var map = main[mode][i]; var map = mappings[i];
for (var j = 0; j < map.names.length; j++) for (var j = 0; j < map.names.length; j++)
{ {
if (map.names[j].indexOf(cmd) == 0) if (map.names[j].indexOf(cmd) == 0)
matching.push(map) matches.push(map)
} }
} }
return matching; return matches;
} }
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// DEFAULT MAPPINGS //////////////////////////////////////// ////////////////////// DEFAULT MAPPINGS ////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
/* /*
* Normal mode * Normal mode
*/ */