|
480 | 480 | ...CM.completionKeymap, |
481 | 481 | /* Search */ |
482 | 482 | ...CM.searchKeymap, |
483 | | - /* Ctrl/Cmd + Enter → Run Code */ |
| 483 | + /* Ctrl/Cmd + Enter or Ctrl/Cmd + Shift + Enter → Run Code */ |
484 | 484 | { |
485 | 485 | key: "Ctrl-Enter", |
486 | 486 | mac: "Cmd-Enter", |
|
489 | 489 | return true; |
490 | 490 | }, |
491 | 491 | }, |
| 492 | + { |
| 493 | + key: "Ctrl-Shift-Enter", |
| 494 | + mac: "Cmd-Shift-Enter", |
| 495 | + run: function () { |
| 496 | + runCode(); |
| 497 | + return true; |
| 498 | + }, |
| 499 | + }, |
| 500 | + /* Ctrl/Cmd + Shift + L → Clear Console */ |
| 501 | + { |
| 502 | + key: "Ctrl-Shift-l", |
| 503 | + mac: "Cmd-Shift-l", |
| 504 | + run: function () { |
| 505 | + resetConsole(); |
| 506 | + return true; |
| 507 | + }, |
| 508 | + }, |
492 | 509 | ]), |
493 | 510 |
|
494 | 511 | /* Update listener — keeps `editor.value` semantic alive */ |
|
1004 | 1021 | }); |
1005 | 1022 | } |
1006 | 1023 |
|
1007 | | - // Keyboard shortcut for copy: Ctrl+Shift+C in editor |
1008 | | - if (cmView) { |
1009 | | - document.addEventListener("keydown", function (event) { |
1010 | | - if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.code === "KeyC") { |
1011 | | - // Check if focus is in the editor |
1012 | | - if ( |
1013 | | - editorMount && |
1014 | | - (editorMount.contains(document.activeElement) || |
1015 | | - document.activeElement === editorMount) |
1016 | | - ) { |
1017 | | - event.preventDefault(); |
1018 | | - if (copyEditorCodeBtn) { |
1019 | | - copyEditorCodeBtn.click(); |
1020 | | - } |
| 1024 | + /* ────────────────────────────────────────────────────────────── |
| 1025 | + Keyboard Shortcuts — Issue #1716 & Issue #1215 |
| 1026 | + - Ctrl/Cmd + Enter: Run Python Code |
| 1027 | + - Ctrl/Cmd + Shift + L: Clear Output Console |
| 1028 | + - Ctrl/Cmd + Shift + C: Copy Code (when focused in editor) |
| 1029 | + ────────────────────────────────────────────────────────────── */ |
| 1030 | + document.addEventListener("keydown", function (event) { |
| 1031 | + if (event.defaultPrevented) return; |
| 1032 | + |
| 1033 | + // Only process if playground section is active/visible |
| 1034 | + if (!playgroundSection || playgroundSection.style.display === "none") return; |
| 1035 | + |
| 1036 | + var isMod = event.ctrlKey || event.metaKey; |
| 1037 | + if (!isMod) return; |
| 1038 | + |
| 1039 | + // Ctrl/Cmd + Shift + C: Copy editor code |
| 1040 | + if ( |
| 1041 | + event.shiftKey && |
| 1042 | + (event.key === "c" || event.key === "C" || event.code === "KeyC") |
| 1043 | + ) { |
| 1044 | + if ( |
| 1045 | + editorMount && |
| 1046 | + (editorMount.contains(document.activeElement) || |
| 1047 | + document.activeElement === editorMount) |
| 1048 | + ) { |
| 1049 | + event.preventDefault(); |
| 1050 | + if (copyEditorCodeBtn) { |
| 1051 | + copyEditorCodeBtn.click(); |
1021 | 1052 | } |
1022 | 1053 | } |
1023 | | - }); |
1024 | | - } |
| 1054 | + return; |
| 1055 | + } |
| 1056 | + |
| 1057 | + // Ctrl/Cmd + Enter: Run Code |
| 1058 | + if (event.key === "Enter" || event.code === "Enter") { |
| 1059 | + event.preventDefault(); |
| 1060 | + runCode(); |
| 1061 | + return; |
| 1062 | + } |
| 1063 | + |
| 1064 | + // Ctrl/Cmd + Shift + L: Clear Output Console |
| 1065 | + if ( |
| 1066 | + event.shiftKey && |
| 1067 | + (event.key === "l" || event.key === "L" || event.code === "KeyL") |
| 1068 | + ) { |
| 1069 | + event.preventDefault(); |
| 1070 | + resetConsole(); |
| 1071 | + return; |
| 1072 | + } |
| 1073 | + }); |
1025 | 1074 | if (saveDraftBtn) { |
1026 | 1075 | saveDraftBtn.addEventListener("click", function () { |
1027 | 1076 | var draftName = prompt("Enter a name for this draft:"); |
|
0 commit comments