Skip to content

Commit e20425e

Browse files
authored
Implement cmd/ctrl + enter shortcut for running code with hover tip (#56)
Hovering over the "Run" button now shows this hint, and the keyboard shortcut now toggles Play/Stop: <img width="97" height="75" alt="image" src="https://github.com/user-attachments/assets/3b977085-5f7b-4a91-9a5b-b43aa1340278" />
1 parent 92ddb0e commit e20425e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/lib/components/TabBar.svelte

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
2020
// Delay before showing stop button to avoid flash on fast scripts
2121
let showStopButton = $state(false);
22-
22+
23+
const isMac = /Mac/i.test(navigator.platform);
24+
const runShortcut = isMac ? '⌘↵' : 'Ctrl+↵';
25+
2326
$effect(() => {
2427
if (!$isRunning) {
2528
showStopButton = false;
@@ -244,12 +247,12 @@
244247
<span class="hidden sm:inline">Check</span>
245248
<span class="sm:hidden"><Icon name="check"size={16} /></span>
246249
</Button>
247-
<Button
248-
size="sm"
249-
variant={showStopButton ? 'secondary' : 'default'}
250-
onclick={handleRun}
251-
class="px-2 sm:px-3"
252-
title={showStopButton ? 'Stop execution' : 'Run code'}
250+
<Button
251+
size="sm"
252+
variant={showStopButton ? 'secondary' : 'default'}
253+
onclick={handleRun}
254+
class="px-2 sm:px-3"
255+
title={showStopButton ? 'Stop execution' : `Run code (${runShortcut})`}
253256
>
254257
<span class="sm:mr-1"><Icon name={showStopButton ? 'stop' : 'play'} size={16} /></span>
255258
<span class="hidden sm:inline">{showStopButton ? 'Stop' : 'Run'}</span>

src/lib/editor/setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { luauLspExtensions } from './lspExtensions';
1919
import { luauEnterKeymap, luauIndentation } from './luauBlocks';
2020
import { forceLinting, lintGutter } from '@codemirror/lint';
2121
import { themeMode } from '$lib/utils/theme';
22-
import { cursorLine } from '$lib/stores/playground';
22+
import { cursorLine, isRunning } from '$lib/stores/playground';
23+
import { runCode, stopExecution } from '$lib/luau/wasm';
2324
import { get } from 'svelte/store';
2425

2526
let editorView: EditorView | null = null;
@@ -66,6 +67,7 @@ function createExtensions(onChange: (content: string) => void): Extension[] {
6667
keymap.of([
6768
...luauEnterKeymap,
6869
...closeBracketsKeymap,
70+
{ key: 'Mod-Enter', run: () => { get(isRunning) ? stopExecution() : runCode(); return true; } },
6971
...defaultKeymap,
7072
...searchKeymap,
7173
...historyKeymap,

0 commit comments

Comments
 (0)