mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 13:55:41 +01:00
Add keyboard shortcut to run playground code
This commit is contained in:
parent
b5a0ee71c2
commit
a279c9d743
1 changed files with 19 additions and 1 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var isMac = /Mac/i.test(navigator.userAgent);
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
require(['vs/editor/editor.main'], function () {
|
require(['vs/editor/editor.main'], function () {
|
||||||
xhr('playground/monaco.d.ts.txt').then(function (response) {
|
xhr('playground/monaco.d.ts.txt').then(function (response) {
|
||||||
|
|
@ -157,8 +158,11 @@
|
||||||
htmlTab.onclick = function () { changeTab(htmlTab, 'html'); };
|
htmlTab.onclick = function () { changeTab(htmlTab, 'html'); };
|
||||||
tabArea.appendChild(htmlTab);
|
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.className = 'action run';
|
||||||
|
runBtn.setAttribute('role', 'button');
|
||||||
|
runBtn.setAttribute('aria-label', runLabel);
|
||||||
runBtn.appendChild(document.createTextNode('Run'));
|
runBtn.appendChild(document.createTextNode('Run'));
|
||||||
runBtn.onclick = function () { run(); };
|
runBtn.onclick = function () { run(); };
|
||||||
tabArea.appendChild(runBtn);
|
tabArea.appendChild(runBtn);
|
||||||
|
|
@ -307,6 +311,20 @@
|
||||||
function run() {
|
function run() {
|
||||||
doRun(runContainer);
|
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;
|
var runIframe = null, runIframeHeight = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue