1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 20:52:26 +01:00

new setCustomMode for plugin writers

This commit is contained in:
Marco Candrian
2008-01-04 11:50:49 +00:00
parent bd66b8522e
commit 9156dc4531
3 changed files with 46 additions and 5 deletions

View File

@@ -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 != "<Esc>" && key != "<C-[>")
{
// 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;

View File

@@ -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

View File

@@ -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 = <str> string to show on v.modes.CUSTOM
// v.plugins.stop = <func> hooked on a v.modes.reset()
// v.plugins.onEvent = <func> function triggered, on keypresses (unless <esc>) (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); });