diff --git a/content/events.js b/content/events.js index e6096288..84b9d31b 100644 --- a/content/events.js +++ b/content/events.js @@ -202,7 +202,7 @@ vimperator.Events = function () //{{{ }, false); tabcontainer.addEventListener("TabSelect", function (event) { - if (vimperator.mode == vimperator.modes.HINTS) + if (vimperator.mode == vimperator.modes.HINTS || vimperator.mode == vimperator.modes.CUSTOM ) vimperator.modes.reset(); vimperator.commandline.clear(); @@ -796,6 +796,7 @@ vimperator.Events = function () //{{{ switch (vimperator.mode) { case vimperator.modes.HINTS: + case vimperator.modes.CUSTOM: case vimperator.modes.COMMAND_LINE: vimperator.modes.reset(); break; @@ -957,9 +958,17 @@ vimperator.Events = function () //{{{ // } }}} - // if Hit-a-hint mode is on, special handling of keys is required if (key != "" && key != "") { + // custom mode... + if (vimperator.mode == vimperator.modes.CUSTOM) + { + vimperator.plugins.onEvent(event); + event.preventDefault(); + event.stopPropagation(); + return false; + } + // if Hit-a-hint mode is on, special handling of keys is required if (vimperator.mode == vimperator.modes.HINTS) { vimperator.hints.onEvent(event); @@ -969,6 +978,16 @@ vimperator.Events = function () //{{{ } } + //FIXME (maybe): (is an ESC or C-] here): on HINTS mode, it enters + //into 'if (map && !skipMap) below. With that (or however) it + //triggers the onEscape part, where it resets mode. Here I just + //return true, with the effect that it also gets to there (for + //whatever reason). if that happens to be correct, well.. + //XXX: why not just do that as well for HINTS mode actually? + + if (vimperator.mode == vimperator.modes.CUSTOM) + return true; + var countStr = vimperator.input.buffer.match(/^[0-9]*/)[0]; var candidateCommand = (vimperator.input.buffer + key).replace(countStr, ""); var map; diff --git a/content/modes.js b/content/modes.js index 9c4a08da..7b7bcdbf 100644 --- a/content/modes.js +++ b/content/modes.js @@ -77,6 +77,8 @@ vimperator.modes = (function () //{{{ return "-- CARET" + ext; case vimperator.modes.TEXTAREA: return "-- TEXTAREA" + ext; + case vimperator.modes.CUSTOM: + return "-- " + vimperator.plugins.mode + ext; default: // NORMAL mode if (vimperator.modes.isRecording) return "recording"; @@ -117,6 +119,10 @@ vimperator.modes = (function () //{{{ vimperator.editor.unselectText(); break; + case vimperator.modes.CUSTOM: + vimperator.plugins.stop(); + break; + case vimperator.modes.HINTS: vimperator.hints.hide(); break; @@ -153,6 +159,7 @@ vimperator.modes = (function () //{{{ COMMAND_LINE: 1 << 4, CARET: 1 << 5, // text cursor is visible TEXTAREA: 1 << 6, // text cursor is in a HTMLTextAreaElement + CUSTOM: 1 << 7, // extended modes, can include multiple modes, and even main modes EX: 1 << 10, INPUT_MULTILINE: 1 << 11, @@ -169,8 +176,8 @@ vimperator.modes = (function () //{{{ __iterator__: function () { - var modes = [this.NONE, this.NORMAL, this.INSERT, this.VISUAL, - this.HINTS, this.COMMAND_LINE, this.CARET, this.TEXTAREA]; + var modes = [this.NONE, this.NORMAL, this.INSERT, this.VISUAL, this.HINTS, + this.COMMAND_LINE, this.CARET, this.TEXTAREA, this.CUSTOM]; for (var i = 0; i < modes.length; i++) yield modes[i]; @@ -193,7 +200,16 @@ vimperator.modes = (function () //{{{ if (main == vimperator.modes.COMMAND_LINE) return; - vimperator.commandline.echo(getModeMessage(), vimperator.commandline.HL_MODEMSG, vimperator.commandline.DISALLOW_MULTILINE); + vimperator.commandline.echo(getModeMessage(), vimperator.commandline.HL_MODEMSG, + vimperator.commandline.DISALLOW_MULTILINE); + }, + + setCustomMode: function (modestr, oneventfunc, stopfunc) + { + // TODO this.plugin[id]... ('id' maybe submode or what..) + vimperator.plugins.mode = modestr; + vimperator.plugins.onEvent = oneventfunc; + vimperator.plugins.stop = stopfunc; }, // helper function to set both modes in one go diff --git a/content/vimperator.js b/content/vimperator.js index 4b007c10..6a545823 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -629,6 +629,12 @@ const vimperator = (function () //{{{ vimperator.globalVariables = {}; + // namespace for plugins/scripts. Actually (only) the active plugin must/can set a + // v.plugins.mode = string to show on v.modes.CUSTOM + // v.plugins.stop = hooked on a v.modes.reset() + // v.plugins.onEvent = function triggered, on keypresses (unless ) (see events.js) + vimperator.plugins = {}; + // TODO: move elsewhere vimperator.registerCallback("submit", vimperator.modes.EX, function (command) { vimperator.execute(command); }); vimperator.registerCallback("complete", vimperator.modes.EX, function (str) { return vimperator.completion.exTabCompletion(str); });