mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 22:22:27 +01:00
new setCustomMode for plugin writers
This commit is contained in:
@@ -202,7 +202,7 @@ vimperator.Events = function () //{{{
|
|||||||
}, false);
|
}, false);
|
||||||
tabcontainer.addEventListener("TabSelect", function (event)
|
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.modes.reset();
|
||||||
|
|
||||||
vimperator.commandline.clear();
|
vimperator.commandline.clear();
|
||||||
@@ -796,6 +796,7 @@ vimperator.Events = function () //{{{
|
|||||||
switch (vimperator.mode)
|
switch (vimperator.mode)
|
||||||
{
|
{
|
||||||
case vimperator.modes.HINTS:
|
case vimperator.modes.HINTS:
|
||||||
|
case vimperator.modes.CUSTOM:
|
||||||
case vimperator.modes.COMMAND_LINE:
|
case vimperator.modes.COMMAND_LINE:
|
||||||
vimperator.modes.reset();
|
vimperator.modes.reset();
|
||||||
break;
|
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-[>")
|
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)
|
if (vimperator.mode == vimperator.modes.HINTS)
|
||||||
{
|
{
|
||||||
vimperator.hints.onEvent(event);
|
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 countStr = vimperator.input.buffer.match(/^[0-9]*/)[0];
|
||||||
var candidateCommand = (vimperator.input.buffer + key).replace(countStr, "");
|
var candidateCommand = (vimperator.input.buffer + key).replace(countStr, "");
|
||||||
var map;
|
var map;
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ vimperator.modes = (function () //{{{
|
|||||||
return "-- CARET" + ext;
|
return "-- CARET" + ext;
|
||||||
case vimperator.modes.TEXTAREA:
|
case vimperator.modes.TEXTAREA:
|
||||||
return "-- TEXTAREA" + ext;
|
return "-- TEXTAREA" + ext;
|
||||||
|
case vimperator.modes.CUSTOM:
|
||||||
|
return "-- " + vimperator.plugins.mode + ext;
|
||||||
default: // NORMAL mode
|
default: // NORMAL mode
|
||||||
if (vimperator.modes.isRecording)
|
if (vimperator.modes.isRecording)
|
||||||
return "recording";
|
return "recording";
|
||||||
@@ -117,6 +119,10 @@ vimperator.modes = (function () //{{{
|
|||||||
vimperator.editor.unselectText();
|
vimperator.editor.unselectText();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case vimperator.modes.CUSTOM:
|
||||||
|
vimperator.plugins.stop();
|
||||||
|
break;
|
||||||
|
|
||||||
case vimperator.modes.HINTS:
|
case vimperator.modes.HINTS:
|
||||||
vimperator.hints.hide();
|
vimperator.hints.hide();
|
||||||
break;
|
break;
|
||||||
@@ -153,6 +159,7 @@ vimperator.modes = (function () //{{{
|
|||||||
COMMAND_LINE: 1 << 4,
|
COMMAND_LINE: 1 << 4,
|
||||||
CARET: 1 << 5, // text cursor is visible
|
CARET: 1 << 5, // text cursor is visible
|
||||||
TEXTAREA: 1 << 6, // text cursor is in a HTMLTextAreaElement
|
TEXTAREA: 1 << 6, // text cursor is in a HTMLTextAreaElement
|
||||||
|
CUSTOM: 1 << 7,
|
||||||
// extended modes, can include multiple modes, and even main modes
|
// extended modes, can include multiple modes, and even main modes
|
||||||
EX: 1 << 10,
|
EX: 1 << 10,
|
||||||
INPUT_MULTILINE: 1 << 11,
|
INPUT_MULTILINE: 1 << 11,
|
||||||
@@ -169,8 +176,8 @@ vimperator.modes = (function () //{{{
|
|||||||
|
|
||||||
__iterator__: function ()
|
__iterator__: function ()
|
||||||
{
|
{
|
||||||
var modes = [this.NONE, this.NORMAL, this.INSERT, this.VISUAL,
|
var modes = [this.NONE, this.NORMAL, this.INSERT, this.VISUAL, this.HINTS,
|
||||||
this.HINTS, this.COMMAND_LINE, this.CARET, this.TEXTAREA];
|
this.COMMAND_LINE, this.CARET, this.TEXTAREA, this.CUSTOM];
|
||||||
|
|
||||||
for (var i = 0; i < modes.length; i++)
|
for (var i = 0; i < modes.length; i++)
|
||||||
yield modes[i];
|
yield modes[i];
|
||||||
@@ -193,7 +200,16 @@ vimperator.modes = (function () //{{{
|
|||||||
if (main == vimperator.modes.COMMAND_LINE)
|
if (main == vimperator.modes.COMMAND_LINE)
|
||||||
return;
|
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
|
// helper function to set both modes in one go
|
||||||
|
|||||||
@@ -629,6 +629,12 @@ const vimperator = (function () //{{{
|
|||||||
|
|
||||||
vimperator.globalVariables = {};
|
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
|
// TODO: move elsewhere
|
||||||
vimperator.registerCallback("submit", vimperator.modes.EX, function (command) { vimperator.execute(command); });
|
vimperator.registerCallback("submit", vimperator.modes.EX, function (command) { vimperator.execute(command); });
|
||||||
vimperator.registerCallback("complete", vimperator.modes.EX, function (str) { return vimperator.completion.exTabCompletion(str); });
|
vimperator.registerCallback("complete", vimperator.modes.EX, function (str) { return vimperator.completion.exTabCompletion(str); });
|
||||||
|
|||||||
Reference in New Issue
Block a user