Fix py-editor execute code on ctrl-enter#2385
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. |
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.