slipHQ / run-wasm

Run WASM based code executions in the browser easily
https://www.runwasm.com
Apache License 2.0
468 stars 47 forks source link

Run Code Examples when pressing CMD + Enter or Ctrl + Enter #77

Closed kennethcassel closed 2 years ago

kennethcassel commented 2 years ago

Is your feature request related to a problem? Please describe.

Yup, when playing with the code editor, it'd be much nicer to run the code via a cmd + enter or ctrl+enter instead of having to use the mouse.

Describe the solution you'd like Run code on CMD + Enter, or CTRL + Enter

Describe alternatives you've considered Using the mouse every time to click the button to run my code

hatemhosny commented 2 years ago

you may implement it like this (based on livecodes editor/monaco.ts)

const keyCodes = {
  CtrlEnter: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
  Enter: monaco.KeyCode.Enter,
  UpArrow: monaco.KeyCode.UpArrow,
  DownArrow: monaco.KeyCode.DownArrow,
};

const addKeyBinding = (label: string, keybinding: any, callback: () => void) => {
  editor.addAction({
    id: label,
    label,
    keybindings: [keybinding],
    precondition: '!suggestWidgetVisible && !markersNavigationVisible && !findWidgetVisible',
    run: callback,
  });
};

// use it like that
addKeyBinding('run', keyCodes.CtrlEnter, async () => {
    await run();
  });
shadab14meb346 commented 2 years ago

I am working on it. And the way I am approaching it is. Add an event listener to window. And when ctrl + enter or cmd + enter is clicked I am firing method runCode

kennethcassel commented 2 years ago

Thanks @shadab14meb346 for closing this with #81