From 8b1b17a84f45708aa26e36ce9880dc22179b7fc9 Mon Sep 17 00:00:00 2001 From: Marco Candrian Date: Sun, 16 Dec 2007 00:45:34 +0000 Subject: [PATCH] marco code, not fully functional yet --- content/events.js | 44 +++++++++++++++++++++++++++++++++++++++++--- content/mappings.js | 16 +++++++++++++++- content/modes.js | 3 +++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/content/events.js b/content/events.js index f53a3e83..97a0b28f 100644 --- a/content/events.js +++ b/content/events.js @@ -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 != "" && key != "") - vimperator.input.pendingArgMap.execute(null, vimperator.input.count, key); + tmp.execute(null, vimperator.input.count, key); - vimperator.input.pendingArgMap = null; } else if (map) { diff --git a/content/mappings.js b/content/mappings.js index 4669acc3..509fa94e 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -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 // {{{ diff --git a/content/modes.js b/content/modes.js index 823cfd0d..95168f95 100644 --- a/content/modes.js +++ b/content/modes.js @@ -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 () {