mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 12:37:58 +01:00
fixed/renamed vimperator.events.toString(event);
v.e.is{Accept,Cancel}Key(key) helper functions
This commit is contained in:
@@ -273,9 +273,12 @@ function Events() //{{{
|
|||||||
// a keycode which can be used in mappings
|
// a keycode which can be used in mappings
|
||||||
// e.g. pressing ctrl+n would result in the string "<C-n>"
|
// e.g. pressing ctrl+n would result in the string "<C-n>"
|
||||||
// null if unknown key
|
// 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 = "";
|
var modifier = "";
|
||||||
if (event.ctrlKey)
|
if (event.ctrlKey)
|
||||||
modifier += "C-";
|
modifier += "C-";
|
||||||
@@ -288,6 +291,7 @@ function Events() //{{{
|
|||||||
{
|
{
|
||||||
if (event.shiftKey)
|
if (event.shiftKey)
|
||||||
modifier += "S-";
|
modifier += "S-";
|
||||||
|
|
||||||
for (var i in keyTable)
|
for (var i in keyTable)
|
||||||
{
|
{
|
||||||
if (keyTable[i][0] == event.keyCode)
|
if (keyTable[i][0] == event.keyCode)
|
||||||
@@ -296,7 +300,6 @@ function Events() //{{{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
// special handling of the Space key
|
// special handling of the Space key
|
||||||
else if (event.charCode == 32)
|
else if (event.charCode == 32)
|
||||||
@@ -308,15 +311,27 @@ function Events() //{{{
|
|||||||
// a normal key like a, b, c, 0, etc.
|
// a normal key like a, b, c, 0, etc.
|
||||||
else if (event.charCode > 0)
|
else if (event.charCode > 0)
|
||||||
{
|
{
|
||||||
if (modifier.length > 0 || event.charCode == 32)
|
key = String.fromCharCode(event.charCode);
|
||||||
return "<" + modifier + key + ">";
|
if (modifier.length == 0)
|
||||||
else
|
|
||||||
return key;
|
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()
|
this.onEscape = function()
|
||||||
{
|
{
|
||||||
if (!vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY))
|
if (!vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY))
|
||||||
@@ -332,7 +347,7 @@ function Events() //{{{
|
|||||||
this.onKeyPress = function(event)
|
this.onKeyPress = function(event)
|
||||||
{
|
{
|
||||||
//var key = event.toString()
|
//var key = event.toString()
|
||||||
var key = vimperator.events.eventToString(event);
|
var key = vimperator.events.toString(event);
|
||||||
if (!key)
|
if (!key)
|
||||||
return false;
|
return false;
|
||||||
// sometimes the non-content area has focus, making our keys not work
|
// sometimes the non-content area has focus, making our keys not work
|
||||||
|
|||||||
@@ -339,9 +339,10 @@ function CommandLine() //{{{
|
|||||||
}
|
}
|
||||||
else if (event.type == "keypress")
|
else if (event.type == "keypress")
|
||||||
{
|
{
|
||||||
var key = event.toString();
|
var key = vimperator.events.toString(event);
|
||||||
|
|
||||||
/* user pressed ENTER to carry out a command */
|
/* 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;
|
echo_allowed = true;
|
||||||
addToHistory(command);
|
addToHistory(command);
|
||||||
@@ -352,7 +353,7 @@ function CommandLine() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* user pressed ESCAPE to cancel this prompt */
|
/* 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");
|
var res = vimperator.triggerCallback("cancel");
|
||||||
// the command history item is saved in the blur() handler
|
// the command history item is saved in the blur() handler
|
||||||
@@ -544,10 +545,8 @@ function CommandLine() //{{{
|
|||||||
|
|
||||||
this.onMultilineInputEvent = function(event)
|
this.onMultilineInputEvent = function(event)
|
||||||
{
|
{
|
||||||
// for now we just receive keypress events
|
var key = vimperator.events.toString(event);
|
||||||
|
if (vimperator.events.isAcceptKey(key))
|
||||||
var key = event.toString();
|
|
||||||
if (key == "<Return>" || key == "<C-j>" || key == "<C-m>")
|
|
||||||
{
|
{
|
||||||
//var lines = multiline_input_widget.value.substr(0, multiline_input_widget.selectionStart).split(/\n/);
|
//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);
|
var text = multiline_input_widget.value.substr(0, multiline_input_widget.selectionStart);
|
||||||
@@ -562,8 +561,8 @@ function CommandLine() //{{{
|
|||||||
|
|
||||||
this.onMultilineOutputEvent = function(event)
|
this.onMultilineOutputEvent = function(event)
|
||||||
{
|
{
|
||||||
var key = event.toString();
|
var key = vimperator.events.toString(event);
|
||||||
if (key == "<Return>" || key == "<C-j>" || key == "<C-m>")
|
if (vimperator.events.isAcceptKey(key))
|
||||||
{
|
{
|
||||||
multiline_output_widget.collapsed = true;
|
multiline_output_widget.collapsed = true;
|
||||||
vimperator.focusContent();
|
vimperator.focusContent();
|
||||||
|
|||||||
Reference in New Issue
Block a user