-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix py-editor execute code on ctrl-enter #2385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In JS, if you have |
|
OK @jeremykawahara ... I gave it a go and indeed the precedence is somehow misleading because it's not a literal spread, it's an array of literals, which is different ... but because there is a reason I have put const listener = () => !runButton.click();
const editor = new EditorView({
extensions: [
indentUnit.of(indentation),
new Compartment().of(python()),
keymap.of([
{ key: "Ctrl-Enter", run: listener, preventDefault: true },
{ key: "Cmd-Enter", run: listener, preventDefault: true },
{ key: "Shift-Enter", run: listener, preventDefault: true },
...defaultKeymap,
// @see https://codemirror.net/examples/tab/
indentWithTab,
]),
basicSetup,
],
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
parent,
doc,
});would this work good enough? we really would like not to break previous expectations, this way |
|
Yep this works as well! Moving This looks good to me! I do believe that
FYI it seemed to work in <html lang="en">
<head>
<!-- Shift-Enter executes code -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.9.2/core.css" />
<script type="module" src="https://pyscript.net/releases/2024.9.2/core.js"></script>
<!-- Shift-Enter does not execute code and only adds a new line -->
<!-- <link rel="stylesheet" href="https://pyscript.net/releases/2024.10.1/core.css" />
<script type="module" src="https://pyscript.net/releases/2024.10.1/core.js"></script> -->
</head>
<body>
<script type="mpy-editor">
print("Hello!")
</script>
</body>
</html> |
|
heh, I guess that's due library changes behind the scene ... I am good with my proposed changes so, please:
Then I'll run the whole thing and approve, once green, thank you! |
e051d93 to
3fd9e84
Compare
|
@WebReflection thanks - updated! Hope I did the rebase correctly. |
WebReflection
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🙏
Description
Really enjoying trying out PyScript! Thanks for this making available!
Currently,
py-editorwith CodeMirror does not execute code onshift-enterorctrl-enter, and instead only adds a new line.I believe the problem is that
defaultKeymapoverrides the custom key mapping.From my understanding,
defaultKeymapis not necessary as the default command bindings are already included in the basicSetup.After removing
defaultKeymap, the code is executed; however, it will also insert a newline.We can prevent the newline by having the listener return true.
Changes
defaultKeymaplistenerreturnstruedistfolder intests/manualChecklist
make buildworks locally.