diff --git a/chrome/content/vimperator/events.js b/chrome/content/vimperator/events.js index 9eb1927f..b8649a7e 100644 --- a/chrome/content/vimperator/events.js +++ b/chrome/content/vimperator/events.js @@ -273,9 +273,12 @@ function Events() //{{{ // a keycode which can be used in mappings // e.g. pressing ctrl+n would result in the string "" // 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 == "" || key == "" || key == ""); + } + this.isCancelKey = function(key) + { + return (key == "" || key == "" || key == ""); + } + 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 diff --git a/chrome/content/vimperator/ui.js b/chrome/content/vimperator/ui.js index d5b5420b..2f59815b 100644 --- a/chrome/content/vimperator/ui.js +++ b/chrome/content/vimperator/ui.js @@ -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 == "" || key == "" || key == "") + 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 == "" || key == "" || key == "") + 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 == "" || key == "" || key == "") + 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 == "" || key == "" || key == "") + var key = vimperator.events.toString(event); + if (vimperator.events.isAcceptKey(key)) { multiline_output_widget.collapsed = true; vimperator.focusContent();