microbit-foundation / python-editor-v3

Micro:bit Educational Foundation Python Editor V3
https://python.microbit.org
MIT License
57 stars 36 forks source link

[dnd] Add ability to append to code block and handle blank line spaces #963

Closed microbit-robert closed 2 years ago

microbit-robert commented 2 years ago

Closes #856. Closes #812. Closes #800. Closes #539.

github-actions[bot] commented 2 years ago

Preview build will be at https://review-python-editor-v3.microbit.org/dnd-fixes/

microbit-robert commented 2 years ago

Slight issue with "while smooshing". while is lost if appending one line below existing while block, but returns two lines below existing while block and beyond.

microbit-robert commented 2 years ago

Slight issue with "while smooshing". while is lost if appending one line below existing while block, but returns two lines below existing while block and beyond.

There appears to be a bug in the isInWhileTrueTree function where the tree believes it is in a while statement when it is not. Most easily observed when add new lines below a while True loop and then dragging and new while True example from bottom to top.

microbit-matt-hillsdon commented 2 years ago

Rebased so it deploys properly.

microbit-matt-hillsdon commented 2 years ago

This works well, though it doesn't really fix https://github.com/microbit-foundation/python-editor-v3/issues/812 how I was expecting. That issue refers to using the horizontal position to influence the indent to span to some existing level.

There's an inconsistency in this change in terms of appending to an existing block:

# Imports go at the top
from microbit import *

if accelerometer.was_gesture("shake"):
    display.show(Image.MEH)
    sleep(1000)

while True:
    if accelerometer.was_gesture("shake"):
        display.show(Image.MEH)
        sleep(1000)
    display.show(Image.HAPPY)

Dragging after the first sleep(1000) nests in the if.

Dragging after the second nests in the while.

It feels as if the logic should be the same.

Previously both cases placed outside the if.

microbit-matt-hillsdon commented 2 years ago

Superseded by https://github.com/microbit-foundation/python-editor-v3/pull/1037 which avoids this issue and allow the user control over the ambiguity in https://github.com/microbit-foundation/python-editor-v3/issues/812.