Fix keyboard event handling

This commit is contained in:
~lucidiot 2022-09-19 00:24:17 +02:00
parent 0894879337
commit a2c366a81a
1 changed files with 7 additions and 4 deletions

View File

@ -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();
}
}