Added the ability to run the code by pressing CMD/Ctrl+Enter#23
Added the ability to run the code by pressing CMD/Ctrl+Enter#23egfanboy wants to merge 3 commits intoitaditya:masterfrom
Conversation
client/components/submitProgram.js
Outdated
| (() => { | ||
| //DOM binding | ||
| submitProgramElem = document.getElementById('submitBtn'); | ||
| editorElement = document.getElementById('editor'); |
There was a problem hiding this comment.
@EricTurf in this project I'm using pub-sub design pattern to enable proper Separation of Concerns. Each component is responsible to deal with their own DOM. submitProgram component shouldn't querySelect the codeEditor component.
The components interact with each other by dispatching events and subscribing to events.
What you have to do is in the codeEditor component, add the _keyDown event listener and the whole CMD + P logic. When you detect that it was indeed CMD + P you dispatch an event say codeEditor:runcode.
Then in the submitProgram component, listen to the codeEditor:runcode event using addEvent helper. When the codeEditor:runcode is triggered, you have to call the _onClick method.
There was a problem hiding this comment.
For reference see how submitProgram and langSel components interact with each other.
|
@EricTurf, pub-sub design pattern is pretty advanced stuff, so don't worry if you feel overwhelmed. If you get stuck, ask me without any hesitance. The objective is that you learn something new. |
|
@itaditya Pushed changes based on your comments. |
|
|
||
| let MacCMDPressed = false; | ||
|
|
||
| const MacCommandKeys = ['MetaLeft', 'MetaRight']; |
There was a problem hiding this comment.
So for mac if you want to run the code using the Command key you cannot use the normal event.ctrlKey + enter to run the command.
The key to the left and right Command keys on MAC are MetaLeft/Right so if you pressed the Command key it will set MacCMDPressed to true and if your next keystroke is enter it will run the command.
On any key that is not MetaLeft/Right it will set MacCMDPressed back to false
Fixes #22
CMD + ENTERorCTRL + EnterI also added
nodemonas a dev dependency since everyone would need to have it installed globally. I can remove if you want.