mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 21:17:59 +01:00
marco code, not fully functional yet
This commit is contained in:
@@ -245,6 +245,10 @@ vimperator.Events = function () //{{{
|
||||
}
|
||||
}
|
||||
|
||||
var macros = {};
|
||||
var isRecording = false;
|
||||
var currentMacro;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
@@ -253,6 +257,23 @@ vimperator.Events = function () //{{{
|
||||
|
||||
wantsModeReset: true, // used in onFocusChange since Firefox is so buggy here
|
||||
|
||||
startRecording: function (reg)
|
||||
{
|
||||
isRecording = true;
|
||||
vimperator.modes.add(vimperator.modes.RECORDING);
|
||||
currentMacro = reg;
|
||||
macros[currentMacro] = "";
|
||||
vimperator.echo("recording into register " + currentMacro + "...");
|
||||
},
|
||||
|
||||
playMacro: function (reg)
|
||||
{
|
||||
if (macros[reg])
|
||||
vimperator.events.feedkeys(macros[reg], true); // true -> noremap
|
||||
else
|
||||
vimperator.echoerr("Register '" + reg + " not set");
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
// removeEventListeners() to avoid mem leaks
|
||||
@@ -570,6 +591,23 @@ vimperator.Events = function () //{{{
|
||||
if (!key)
|
||||
return true;
|
||||
|
||||
if (isRecording)
|
||||
{
|
||||
if (key == "q") // TODO: should not be hardcoded
|
||||
{
|
||||
isRecording = false;
|
||||
vimperator.modes.remove(vimperator.modes.RECORDING);
|
||||
vimperator.echo("recorded " + currentMacro + " : " + macros[currentMacro]); // DEBUG:
|
||||
event.preventDefault(); // XXX: or howto stop that key beeing processed?
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
else if (!vimperator.mappings.hasMap(vimperator.mode, vimperator.input.buffer + key))
|
||||
{
|
||||
macros[currentMacro] += key;
|
||||
}
|
||||
}
|
||||
|
||||
var stop = true; // set to false if we should NOT consume this event but let also firefox handle it
|
||||
|
||||
var win = document.commandDispatcher.focusedWindow;
|
||||
@@ -673,11 +711,11 @@ vimperator.Events = function () //{{{
|
||||
else if (vimperator.input.pendingArgMap)
|
||||
{
|
||||
vimperator.input.buffer = "";
|
||||
|
||||
var tmp = vimperator.input.pendingArgMap; // must be set to null before .execute; if not
|
||||
vimperator.input.pendingArgMap = null; // v.inputpendingArgMap is still 'true' also for new feeded keys
|
||||
if (key != "<Esc>" && key != "<C-[>")
|
||||
vimperator.input.pendingArgMap.execute(null, vimperator.input.count, key);
|
||||
tmp.execute(null, vimperator.input.count, key);
|
||||
|
||||
vimperator.input.pendingArgMap = null;
|
||||
}
|
||||
else if (map)
|
||||
{
|
||||
|
||||
@@ -1290,7 +1290,21 @@ vimperator.Mappings = function () //{{{
|
||||
help: "Repeat the last search 1 time (until count is supported) in the opposite direction."
|
||||
}
|
||||
));
|
||||
|
||||
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["q"],
|
||||
function (arg) { vimperator.events.startRecording(arg); },
|
||||
{
|
||||
shortHelp: "record a macro into a register",
|
||||
help: "record a macro; [a-zA-Z0-9] are valid registers",
|
||||
flags: vimperator.Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["@"],
|
||||
function (arg) { vimperator.events.playMacro(arg); },
|
||||
{
|
||||
shortHelp: "play a macro",
|
||||
flags: vimperator.Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
// }}}
|
||||
// HINTS mode
|
||||
// {{{
|
||||
|
||||
@@ -56,6 +56,8 @@ vimperator.modes = (function () //{{{
|
||||
ext = " (always)"; break;
|
||||
case vimperator.modes.MENU: // TODO: desirable?
|
||||
ext = " (menu)"; break;
|
||||
case vimperator.modes.RECORDING:
|
||||
ext = " (recording)"; break;
|
||||
}
|
||||
|
||||
switch (main)
|
||||
@@ -153,6 +155,7 @@ vimperator.modes = (function () //{{{
|
||||
ALWAYS_HINT: 1 << 17,
|
||||
MENU: 1 << 18, // a popupmenu is active
|
||||
LINE: 1 << 19, // linewise visual mode
|
||||
RECORDING: 1 << 20,
|
||||
|
||||
__iterator__: function ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user