adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.11k stars 1.22k forks source link

Web serial input thrown off by left arrow #6609

Open FoamyGuy opened 2 years ago

FoamyGuy commented 2 years ago

CircuitPython version

Build from current main ESP32-S2 TFT.

Code/REPL

print("hi")

But with arrow keys used to move cursor after the parens.

Behavior

The left arrow does move the cursor in the input box, but the text getting sent to serial doesn't come out the same, it seems to be missing the left arrow presses that changed the location of the cursor.

Description

No response

Additional information

https://user-images.githubusercontent.com/2406189/179326903-9564d0a2-2b0d-4d57-a9c6-ec011d02e9c1.mp4

FoamyGuy commented 2 years ago

https://user-images.githubusercontent.com/2406189/179326903-9564d0a2-2b0d-4d57-a9c6-ec011d02e9c1.mp4

tannewt commented 2 years ago

I'm not sure what the right thing to do here is. We could send extra characters to delete and send the rest of the line. I'm worried it's going to add a lot of logic. This might be a case that the full serial on code.circuitpython.org is better to use.

makermelissa commented 1 year ago

My first thought is I would probably just listen to the keydown event for arrows and send it via serial.

However, there are some other cases to watch out for:

  1. Clicking on different locations with the mouse moves the cursor and it's a different variation of the same problem.
  2. Pasting text in can present another similar problem and there are a variety of ways to do this, so it's not as easy to prevent. Here are some ways I can think of that this can be done:
    • Pressing Control-V (or Command+V on Mac or Control+Shift+V on Linux)
    • Right clicking and choosing paste
    • Going to the menu and choosing Edit -> Paste

We should be able to disable the mousedown event to fix the mouse cursor problem. For pasting, there's a paste event and we could either prevent anything from being inserted or just send it via serial.

This seems like an interesting challenge. The logic shouldn't add too much to the size.

tannewt commented 1 year ago

I don't think this is important to do because it only impacts the offline serial terminal. I'd rather focus on code.cp.org

makermelissa commented 1 year ago

Right, that's what I'm focusing on. I was just adding my thoughts to the mix.