You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user-guide/editor.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -173,6 +173,47 @@ If a `setup` editor is present, that's the only PyEditor that needs a config.
173
173
Any subsequent related editor will reuse the config parsed and bootstrapped for
174
174
the `setup` editor.
175
175
176
+
## Execution via keyboard
177
+
178
+
Accordingly with the Operating system you are using, a combination of either `Ctrl-Enter`, `Cmd-Enter` or `Shift-Enter` would implicitly execute the code and show results within the `target` output node without ever needing to reach the *Run* button and lose the focus.
179
+
180
+
## Execution Override
181
+
182
+
The editor offers great features even without interpreting code and in some case users would like to just bootstrap an editor then orchestrate what should happen once *Run* button is clicked or any of the keys combined to execute code is pressed.
183
+
184
+
The `handleEvent` attached to the script that bootstraps the editor can be overridden to achieve this with relative ease:
185
+
186
+
```html title="Overriding execution via handleEvent."
187
+
<scripttype="mpy-editor"id="foreign">
188
+
print(6*7)
189
+
</script>
190
+
191
+
<scripttype="mpy">
192
+
from pyscript import document
193
+
194
+
def handle_event(event):
195
+
# will log `print(6 * 7)`
196
+
print(event.code)
197
+
# prevent default execution
198
+
return False
199
+
200
+
foreign =document.getElementById("foreign")
201
+
202
+
foreign.handleEvent= handle_event
203
+
</script>
204
+
```
205
+
206
+
[This live example](https://agiammarchi.pyscriptapps.com/pyeditor-iot-example/latest/) that allows one to play with micro controllers running MicroPython shows how the editor can be used to execute code via serial USB connection.
207
+
208
+
## Tab behavior
209
+
210
+
We are currently trapping the `tab` key in a way that reflects what regular *IDE* do: the code is simply indented, as opposite of losing the focus every single time.
211
+
212
+
We are fully aware of the implications this might have around accessibility so we followed [this detailed Codemirror's documentation](https://codemirror.net/examples/tab/) and allowed that *escape hatch* to be able to explicitly move focus outside the editor when it's meant.
213
+
214
+
That is: press `Esc` before `Tab` to see your focus moving to the next focusable element on the page but by default you can press `Tab` to indent the code as you would expect from your daily editor.
215
+
216
+
176
217
## Still missing
177
218
178
219
The PyEditor is currently under active development and refinement, so features
0 commit comments