mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 18:32:25 +01:00
Add :map <silent>
This commit is contained in:
@@ -851,7 +851,7 @@ function Events() //{{{
|
|||||||
//
|
//
|
||||||
// @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 \\
|
||||||
feedkeys: function (keys, noremap)
|
feedkeys: function (keys, noremap, silent)
|
||||||
{
|
{
|
||||||
var doc = window.document;
|
var doc = window.document;
|
||||||
var view = window.document.defaultView;
|
var view = window.document.defaultView;
|
||||||
@@ -859,74 +859,85 @@ function Events() //{{{
|
|||||||
|
|
||||||
var wasFeeding = this.feedingKeys;
|
var wasFeeding = this.feedingKeys;
|
||||||
this.feedingKeys = true;
|
this.feedingKeys = true;
|
||||||
|
var wasSilent = commandline.silent;
|
||||||
|
if(silent)
|
||||||
|
commandline.silent = silent;
|
||||||
|
|
||||||
noremap = !!noremap;
|
try
|
||||||
|
|
||||||
for (var i = 0; i < keys.length; i++)
|
|
||||||
{
|
{
|
||||||
var charCode = keys.charCodeAt(i);
|
noremap = !!noremap;
|
||||||
var keyCode = 0;
|
|
||||||
var shift = false, ctrl = false, alt = false, meta = false;
|
|
||||||
|
|
||||||
//if (charCode == 92) // the '\' key FIXME: support the escape key
|
for (var i = 0; i < keys.length; i++)
|
||||||
if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
|
|
||||||
{
|
{
|
||||||
var matches = keys.substr(i + 1).match(/([CSMAcsma]-)*([^>]+)/);
|
var charCode = keys.charCodeAt(i);
|
||||||
if (matches && matches[2])
|
var keyCode = 0;
|
||||||
|
var shift = false, ctrl = false, alt = false, meta = false;
|
||||||
|
|
||||||
|
//if (charCode == 92) // the '\' key FIXME: support the escape key
|
||||||
|
if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
|
||||||
{
|
{
|
||||||
if (matches[1]) // check for modifiers
|
var matches = keys.substr(i + 1).match(/([CSMAcsma]-)*([^>]+)/);
|
||||||
|
if (matches && matches[2])
|
||||||
{
|
{
|
||||||
ctrl = /[cC]-/.test(matches[1]);
|
if (matches[1]) // check for modifiers
|
||||||
alt = /[aA]-/.test(matches[1]);
|
{
|
||||||
shift = /[sS]-/.test(matches[1]);
|
ctrl = /[cC]-/.test(matches[1]);
|
||||||
meta = /[mM]-/.test(matches[1]);
|
alt = /[aA]-/.test(matches[1]);
|
||||||
}
|
shift = /[sS]-/.test(matches[1]);
|
||||||
if (matches[2].length == 1)
|
meta = /[mM]-/.test(matches[1]);
|
||||||
{
|
}
|
||||||
if (!ctrl && !alt && !shift && !meta)
|
if (matches[2].length == 1)
|
||||||
return false; // an invalid key like <a>
|
{
|
||||||
charCode = matches[2].charCodeAt(0);
|
if (!ctrl && !alt && !shift && !meta)
|
||||||
}
|
return false; // an invalid key like <a>
|
||||||
else if (matches[2].toLowerCase() == "space")
|
charCode = matches[2].charCodeAt(0);
|
||||||
{
|
}
|
||||||
charCode = 32;
|
else if (matches[2].toLowerCase() == "space")
|
||||||
}
|
{
|
||||||
else if (keyCode = getKeyCode(matches[2]))
|
charCode = 32;
|
||||||
{
|
}
|
||||||
charCode = 0;
|
else if (keyCode = getKeyCode(matches[2]))
|
||||||
}
|
{
|
||||||
else // an invalid key like <A-xxx> was found, stop propagation here (like Vim)
|
charCode = 0;
|
||||||
{
|
}
|
||||||
break;
|
else // an invalid key like <A-xxx> was found, stop propagation here (like Vim)
|
||||||
}
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
i += matches[0].length + 1;
|
i += matches[0].length + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // a simple key
|
||||||
|
{
|
||||||
|
// FIXME: does not work for non A-Z keys like Ö,Ä,...
|
||||||
|
shift = (keys[i] >= "A" && keys[i] <= "Z");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else // a simple key
|
|
||||||
{
|
|
||||||
// FIXME: does not work for non A-Z keys like Ö,Ä,...
|
|
||||||
shift = (keys[i] >= "A" && keys[i] <= "Z");
|
|
||||||
}
|
|
||||||
|
|
||||||
var elem = window.document.commandDispatcher.focusedElement;
|
var elem = window.document.commandDispatcher.focusedElement;
|
||||||
if (!elem)
|
if (!elem)
|
||||||
elem = window.content;
|
elem = window.content;
|
||||||
|
|
||||||
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;
|
evt.noremap = noremap;
|
||||||
evt.isMacro = true;
|
evt.isMacro = true;
|
||||||
elem.dispatchEvent(evt);
|
elem.dispatchEvent(evt);
|
||||||
if (!this.feedingKeys)
|
if (!this.feedingKeys)
|
||||||
break;
|
break;
|
||||||
// stop feeding keys if page loading failed
|
// stop feeding keys if page loading failed
|
||||||
if (modes.isReplaying && !waitForPageLoaded())
|
if (modes.isReplaying && !waitForPageLoaded())
|
||||||
break;
|
break;
|
||||||
// else // a short break between keys often helps
|
// else // a short break between keys often helps
|
||||||
// liberator.sleep(50);
|
// liberator.sleep(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.feedingKeys = wasFeeding;
|
||||||
|
if(silent)
|
||||||
|
commandline.silent = wasSilent;
|
||||||
}
|
}
|
||||||
this.feedingKeys = wasFeeding;
|
|
||||||
return i == keys.length;
|
return i == keys.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -170,14 +170,15 @@ function Mappings() //{{{
|
|||||||
// 2 args -> map arg1 to arg*
|
// 2 args -> map arg1 to arg*
|
||||||
function map(args, mode, noremap)
|
function map(args, mode, noremap)
|
||||||
{
|
{
|
||||||
if (!args)
|
if (!args.arguments.length)
|
||||||
{
|
{
|
||||||
mappings.list(mode);
|
mappings.list(mode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ?:\s+ <- don't remember; (...)? optional = rhs
|
// ?:\s+ <- don't remember; (...)? optional = rhs
|
||||||
var [, lhs, rhs] = args.match(/(\S+)(?:\s+(.+))?/);
|
let [lhs] = args.arguments;
|
||||||
|
let rhs = args.literalArg;
|
||||||
|
|
||||||
if (!rhs) // list the mapping
|
if (!rhs) // list the mapping
|
||||||
{
|
{
|
||||||
@@ -189,11 +190,11 @@ function Mappings() //{{{
|
|||||||
{
|
{
|
||||||
mappings.addUserMap([m], [lhs],
|
mappings.addUserMap([m], [lhs],
|
||||||
"User defined mapping",
|
"User defined mapping",
|
||||||
function (count) { events.feedkeys((count > 1 ? count : "") + rhs, noremap); },
|
function (count) { events.feedkeys((count > 1 ? count : "") + rhs, noremap, "<silent>" in args); },
|
||||||
{
|
{
|
||||||
flags: Mappings.flags.COUNT,
|
flags: Mappings.flags.COUNT,
|
||||||
rhs: rhs,
|
rhs: rhs,
|
||||||
noremap: noremap
|
noremap: noremap,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,10 +202,19 @@ function Mappings() //{{{
|
|||||||
|
|
||||||
modeDescription = modeDescription ? " in " + modeDescription + " mode" : "";
|
modeDescription = modeDescription ? " in " + modeDescription + " mode" : "";
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
completer: function (filter) completion.userMapping(filter, modes),
|
||||||
|
options: [
|
||||||
|
[["<silent>", "<Silent>"], commands.OPTION_NOARG]
|
||||||
|
],
|
||||||
|
argCount: 1,
|
||||||
|
literal: true
|
||||||
|
};
|
||||||
|
|
||||||
commands.add([ch ? ch + "m[ap]" : "map"],
|
commands.add([ch ? ch + "m[ap]" : "map"],
|
||||||
"Map a key sequence" + modeDescription,
|
"Map a key sequence" + modeDescription,
|
||||||
function (args) { map(args, modes, false); },
|
function (args) { map(args, modes, false); },
|
||||||
{ completer: function (filter) completion.userMapping(filter, modes) });
|
opts);
|
||||||
|
|
||||||
commands.add([ch + "no[remap]"],
|
commands.add([ch + "no[remap]"],
|
||||||
"Map a key sequence without remapping keys" + modeDescription,
|
"Map a key sequence without remapping keys" + modeDescription,
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ function CommandLine() //{{{
|
|||||||
};
|
};
|
||||||
var lastMowOutput = null;
|
var lastMowOutput = null;
|
||||||
|
|
||||||
|
var silent = false;
|
||||||
|
|
||||||
var completionList = new ItemList("liberator-completions");
|
var completionList = new ItemList("liberator-completions");
|
||||||
var completions = [];
|
var completions = [];
|
||||||
// for the example command "open sometext| othertext" (| is the cursor pos):
|
// for the example command "open sometext| othertext" (| is the cursor pos):
|
||||||
@@ -108,7 +110,7 @@ function CommandLine() //{{{
|
|||||||
var statusTimer = new util.Timer(5, 100, function ()
|
var statusTimer = new util.Timer(5, 100, function ()
|
||||||
statusline.updateProgress("match " + (completionIndex + 1) + " of " + completions.length));
|
statusline.updateProgress("match " + (completionIndex + 1) + " of " + completions.length));
|
||||||
var autocompleteTimer = new util.Timer(201, 300, function (command) {
|
var autocompleteTimer = new util.Timer(201, 300, function (command) {
|
||||||
if (modes.isReplaying)
|
if (events.feedingKeys)
|
||||||
return;
|
return;
|
||||||
let [start, compl] = completion.ex(command);
|
let [start, compl] = completion.ex(command);
|
||||||
commandline.setCompletions(compl, start);
|
commandline.setCompletions(compl, start);
|
||||||
@@ -549,6 +551,15 @@ function CommandLine() //{{{
|
|||||||
|
|
||||||
get mode() (modes.extended == modes.EX) ? "cmd" : "search",
|
get mode() (modes.extended == modes.EX) ? "cmd" : "search",
|
||||||
|
|
||||||
|
get silent() silent,
|
||||||
|
set silent(val) {
|
||||||
|
silent = val;
|
||||||
|
if(silent)
|
||||||
|
storage.styles.addSheet("silent-mode", "chrome://*", "#liberator-commandline > * { opacity: 0 }", true, true);
|
||||||
|
else
|
||||||
|
storage.styles.removeSheet("silent-mode", null, null, null, true);
|
||||||
|
},
|
||||||
|
|
||||||
getCommand: function ()
|
getCommand: function ()
|
||||||
{
|
{
|
||||||
return commandWidget.value;
|
return commandWidget.value;
|
||||||
@@ -717,7 +728,7 @@ function CommandLine() //{{{
|
|||||||
let mode = currentExtendedMode; // save it here, as setMode() resets it
|
let mode = currentExtendedMode; // save it here, as setMode() resets it
|
||||||
currentExtendedMode = null; /* Don't let modes.pop trigger "cancel" */
|
currentExtendedMode = null; /* Don't let modes.pop trigger "cancel" */
|
||||||
inputHistory.add(command);
|
inputHistory.add(command);
|
||||||
modes.pop(true);
|
modes.pop(!commandline.silent);
|
||||||
autocompleteTimer.reset();
|
autocompleteTimer.reset();
|
||||||
completionList.hide();
|
completionList.hide();
|
||||||
liberator.focusContent(false);
|
liberator.focusContent(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user