Fix keyboard event handling
This commit is contained in:
parent
0894879337
commit
a2c366a81a
11
console.js
11
console.js
|
@ -109,12 +109,11 @@ window.onload = function () {
|
|||
|
||||
var inputLogger = makeLogger('log', 'lightblue');
|
||||
function run () {
|
||||
var selected = getSelectedText(input);
|
||||
var code = selected ? selected : input.value;
|
||||
var code = getSelectedText(input) || input.value;
|
||||
if (!code.trim()) return;
|
||||
inputLogger(code);
|
||||
try {
|
||||
console.log(tryString(eval(code)));
|
||||
console.log(eval(code));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
@ -129,9 +128,13 @@ window.onload = function () {
|
|||
}
|
||||
|
||||
input.onkeypress = function (event) {
|
||||
if (!event) event = window.event;
|
||||
// Run code if Shift+Enter is pressed
|
||||
if (event && event.keyCode === 13 && event.shiftKey) {
|
||||
event.preventDefault();
|
||||
event.cancelBubble = true;
|
||||
event.returnValue = false;
|
||||
if (event.stopPropagation) event.stopPropagation();
|
||||
if (event.preventDefault) event.preventDefault();
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue