mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 00:37:58 +01:00
Add a Map#isUserMap property.
This is symmetrical with Command#isUserCommand although both should probably be renamed #user given the other property names.
This commit is contained in:
@@ -370,11 +370,11 @@ function Commands() //{{{
|
|||||||
return [len - str.length, arg, quote];
|
return [len - str.length, arg, quote];
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCommand(command, isUserCommand, replace)
|
function addCommand(command, replace)
|
||||||
{
|
{
|
||||||
if (exCommands.some(function (c) c.hasName(command.name)))
|
if (exCommands.some(function (c) c.hasName(command.name)))
|
||||||
{
|
{
|
||||||
if (isUserCommand && replace)
|
if (command.isUserCommand && replace)
|
||||||
commands.removeUserCommand(command.name);
|
commands.removeUserCommand(command.name);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -472,7 +472,7 @@ function Commands() //{{{
|
|||||||
*/
|
*/
|
||||||
add: function (names, description, action, extra)
|
add: function (names, description, action, extra)
|
||||||
{
|
{
|
||||||
return addCommand(new Command(names, description, action, extra), false, false);
|
return addCommand(new Command(names, description, action, extra), false);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -493,7 +493,7 @@ function Commands() //{{{
|
|||||||
extra.isUserCommand = true;
|
extra.isUserCommand = true;
|
||||||
description = description || "User defined command";
|
description = description || "User defined command";
|
||||||
|
|
||||||
return addCommand(new Command(names, description, action, extra), true, replace);
|
return addCommand(new Command(names, description, action, extra), replace);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
|||||||
* @param {function} action The action invoked by each key sequence.
|
* @param {function} action The action invoked by each key sequence.
|
||||||
* @param {Object} extraInfo An optional extra configuration hash. The
|
* @param {Object} extraInfo An optional extra configuration hash. The
|
||||||
* following properties are supported.
|
* following properties are supported.
|
||||||
* flags - see {@link Map#flags}
|
* arg - see {@link Map#arg}
|
||||||
|
* count - see {@link Map#count}
|
||||||
|
* motion - see {@link Map#motion}
|
||||||
|
* route - see {@link Map#route}
|
||||||
* noremap - see {@link Map#noremap}
|
* noremap - see {@link Map#noremap}
|
||||||
* rhs - see {@link Map#rhs}
|
* rhs - see {@link Map#rhs}
|
||||||
* silent - see {@link Map#silent}
|
* silent - see {@link Map#silent}
|
||||||
@@ -83,6 +86,12 @@ function Map(modes, keys, description, action, extraInfo) //{{{
|
|||||||
this.silent = extraInfo.silent || false;
|
this.silent = extraInfo.silent || false;
|
||||||
/** @property {string} The literal RHS expansion of this mapping. */
|
/** @property {string} The literal RHS expansion of this mapping. */
|
||||||
this.rhs = extraInfo.rhs || null;
|
this.rhs = extraInfo.rhs || null;
|
||||||
|
/**
|
||||||
|
* @property {boolean} Specifies whether this is a user mapping. User
|
||||||
|
* mappings may be created by plugins, or directly by users. Users and
|
||||||
|
* plugin authors should create only user mappings.
|
||||||
|
*/
|
||||||
|
this.isUserMap = extraInfo.isUserMap || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map.prototype = {
|
Map.prototype = {
|
||||||
@@ -145,9 +154,9 @@ function Mappings() //{{{
|
|||||||
user[mode] = [];
|
user[mode] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function addMap(map, userMap)
|
function addMap(map)
|
||||||
{
|
{
|
||||||
let where = userMap ? user : main;
|
let where = map.isUserMap ? user : main;
|
||||||
map.modes.forEach(function (mode) {
|
map.modes.forEach(function (mode) {
|
||||||
if (!(mode in where))
|
if (!(mode in where))
|
||||||
where[mode] = [];
|
where[mode] = [];
|
||||||
@@ -375,7 +384,7 @@ function Mappings() //{{{
|
|||||||
*/
|
*/
|
||||||
add: function (modes, keys, description, action, extra)
|
add: function (modes, keys, description, action, extra)
|
||||||
{
|
{
|
||||||
addMap(new Map(modes, keys, description, action, extra), false);
|
addMap(new Map(modes, keys, description, action, extra));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -393,6 +402,8 @@ function Mappings() //{{{
|
|||||||
addUserMap: function (modes, keys, description, action, extra)
|
addUserMap: function (modes, keys, description, action, extra)
|
||||||
{
|
{
|
||||||
keys = keys.map(expandLeader);
|
keys = keys.map(expandLeader);
|
||||||
|
extra = extra || {};
|
||||||
|
extra.isUserCommand = true;
|
||||||
let map = new Map(modes, keys, description || "User defined mapping", action, extra);
|
let 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
|
||||||
@@ -402,7 +413,7 @@ function Mappings() //{{{
|
|||||||
removeMap(mode, name);
|
removeMap(mode, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
addMap(map, true);
|
addMap(map);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user