diff --git a/src/resources/assets/js/app.js b/src/resources/assets/js/app.js index 236d651..5725267 100644 --- a/src/resources/assets/js/app.js +++ b/src/resources/assets/js/app.js @@ -6,6 +6,7 @@ editor.on('change', function () { localStorage.setItem('live-tinker', editor.getValue()); }); +// Add keyboard commands editor.commands.addCommand({ name: 'runAll', bindKey: {win: 'Ctrl-Enter', mac: 'Command-Enter'}, @@ -13,16 +14,28 @@ editor.commands.addCommand({ sendCode(editor.getValue()) } }); +editor.commands.addCommand({ + name: 'runSelected', + bindKey: {win: 'Ctrl-Shift-Enter', mac: 'Command-Shift-Enter'}, + exec: function(editor) { + sendCode(editor.getSelectedText()) + } +}); function sendCode(text) { var xhr = new XMLHttpRequest(); xhr.open('POST', '/live-tinker/ajax'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function() { - document.Response.document.body.innerHTML = xhr.responseText; + var response = xhr.responseText; + if (xhr.status === 200) { + response = '
' + response + '
'; + } + + document.Response.document.body.innerHTML = response; changeButtonsState(false); }; - xhr.send('code=' + encodeURIComponent(text)); + xhr.send('c=' + encodeURIComponent(text)); changeButtonsState(true); document.Response.document.body.innerHTML = '';