Skip to content

Commit d9aa4c9

Browse files
committed
Fix #127 - Updated Editor page with latest features
1 parent e3c26f1 commit d9aa4c9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/user-guide/editor.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,47 @@ If a `setup` editor is present, that's the only PyEditor that needs a config.
173173
Any subsequent related editor will reuse the config parsed and bootstrapped for
174174
the `setup` editor.
175175

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+
<script type="mpy-editor" id="foreign">
188+
print(6 * 7)
189+
</script>
190+
191+
<script type="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+
176217
## Still missing
177218

178219
The PyEditor is currently under active development and refinement, so features

0 commit comments

Comments
 (0)