Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground: Add keyboard shortcut to run playground code #1756

Merged
merged 1 commit into from Jan 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion website/playground/playground.js
Expand Up @@ -4,6 +4,7 @@

'use strict';

var isMac = /Mac/i.test(navigator.userAgent);
window.onload = function () {
require(['vs/editor/editor.main'], function () {
xhr('playground/monaco.d.ts.txt').then(function (response) {
Expand Down Expand Up @@ -157,8 +158,11 @@
htmlTab.onclick = function () { changeTab(htmlTab, 'html'); };
tabArea.appendChild(htmlTab);

var runBtn = document.createElement('span');
var runLabel = 'Press ' + (isMac ? 'CMD + return' : 'CTRL + Enter') + ' to run the code.';
var runBtn = document.createElement('button');
runBtn.className = 'action run';
runBtn.setAttribute('role', 'button');
runBtn.setAttribute('aria-label', runLabel);
runBtn.appendChild(document.createTextNode('Run'));
runBtn.onclick = function () { run(); };
tabArea.appendChild(runBtn);
Expand Down Expand Up @@ -307,6 +311,20 @@
function run() {
doRun(runContainer);
}

editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, run);
window.addEventListener('keydown', function keyDown(ev) {
if ((isMac && !ev.metaKey) || !ev.ctrlKey) {
return;
}

if (ev.shiftKey || ev.altKey || ev.keyCode !== 13) {
return;
}

ev.preventDefault();
run();
});
}

var runIframe = null, runIframeHeight = 0;
Expand Down