1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 10:27:58 +01:00

fixed/renamed vimperator.events.toString(event);

v.e.is{Accept,Cancel}Key(key) helper functions
This commit is contained in:
Martin Stubenschrott
2007-08-11 20:05:51 +00:00
parent e91f192a62
commit 5c3a8426b1
2 changed files with 32 additions and 18 deletions

View File

@@ -273,9 +273,12 @@ function Events() //{{{
// a keycode which can be used in mappings
// e.g. pressing ctrl+n would result in the string "<C-n>"
// null if unknown key
this.eventToString = function(event) //{{{
this.toString = function(event) //{{{
{
var key = String.fromCharCode(event.charCode);
if(!event)
return;
var key = null;
var modifier = "";
if (event.ctrlKey)
modifier += "C-";
@@ -288,6 +291,7 @@ function Events() //{{{
{
if (event.shiftKey)
modifier += "S-";
for (var i in keyTable)
{
if (keyTable[i][0] == event.keyCode)
@@ -296,7 +300,6 @@ function Events() //{{{
break;
}
}
return null;
}
// special handling of the Space key
else if (event.charCode == 32)
@@ -308,15 +311,27 @@ function Events() //{{{
// a normal key like a, b, c, 0, etc.
else if (event.charCode > 0)
{
if (modifier.length > 0 || event.charCode == 32)
return "<" + modifier + key + ">";
else
key = String.fromCharCode(event.charCode);
if (modifier.length == 0)
return key;
}
else // a key like F1 is always enclosed in < and >
return "<" + modifier + key + ">";
if (key == null)
return null;
// a key like F1 is always enclosed in < and >
return "<" + modifier + key + ">";
} //}}}
this.isAcceptKey = function(key)
{
return (key == "<Return>" || key == "<C-j>" || key == "<C-m>");
}
this.isCancelKey = function(key)
{
return (key == "<Esc>" || key == "<C-[>" || key == "<C-c>");
}
this.onEscape = function()
{
if (!vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY))
@@ -332,7 +347,7 @@ function Events() //{{{
this.onKeyPress = function(event)
{
//var key = event.toString()
var key = vimperator.events.eventToString(event);
var key = vimperator.events.toString(event);
if (!key)
return false;
// sometimes the non-content area has focus, making our keys not work

View File

@@ -339,9 +339,10 @@ function CommandLine() //{{{
}
else if (event.type == "keypress")
{
var key = event.toString();
var key = vimperator.events.toString(event);
/* user pressed ENTER to carry out a command */
if (key == "<Return>" || key == "<C-j>" || key == "<C-m>")
if (vimperator.events.isAcceptKey(key))
{
echo_allowed = true;
addToHistory(command);
@@ -352,7 +353,7 @@ function CommandLine() //{{{
}
/* user pressed ESCAPE to cancel this prompt */
else if (key == "<Esc>" || key == "<C-[>" || key == "<C-c>")
else if (vimperator.events.isCancelKey(key))
{
var res = vimperator.triggerCallback("cancel");
// the command history item is saved in the blur() handler
@@ -544,10 +545,8 @@ function CommandLine() //{{{
this.onMultilineInputEvent = function(event)
{
// for now we just receive keypress events
var key = event.toString();
if (key == "<Return>" || key == "<C-j>" || key == "<C-m>")
var key = vimperator.events.toString(event);
if (vimperator.events.isAcceptKey(key))
{
//var lines = multiline_input_widget.value.substr(0, multiline_input_widget.selectionStart).split(/\n/);
var text = multiline_input_widget.value.substr(0, multiline_input_widget.selectionStart);
@@ -562,8 +561,8 @@ function CommandLine() //{{{
this.onMultilineOutputEvent = function(event)
{
var key = event.toString();
if (key == "<Return>" || key == "<C-j>" || key == "<C-m>")
var key = vimperator.events.toString(event);
if (vimperator.events.isAcceptKey(key))
{
multiline_output_widget.collapsed = true;
vimperator.focusContent();