scratchfoundation / scratch-gui

Graphical User Interface for creating and running Scratch 3.0 projects.
https://scratchfoundation.github.io/scratch-gui/develop/
BSD 3-Clause "New" or "Revised" License
4.46k stars 3.55k forks source link

Alt+Left does not go back #8395

Open DNin01 opened 2 years ago

DNin01 commented 2 years ago

Expected Behavior

Alt+Left is a browser keyboard shortcut that takes you back to the previous page, just like the Back button.

Actual Behavior

You can't do that. Probably due to the browser believing that it's already doing something on the webpage, so it doesn't go back.

Steps to Reproduce

  1. Go to https://llk.github.io/scratch-gui/develop/ (or a project page on the Scratch website. It can be any project at all, even one that doesn't have any "when key pressed" blocks. Example: https://scratch.mit.edu/projects/10128067/).
  2. Hold the Alt key while pressing the left arrow key.

Nothing happens, other than the project recognizing that you pressed the left arrow key.

System Details/Other

Windows 10 with Edge 101.0.4951.64

This glitch was also reported on Scratch over at https://scratch.mit.edu/discuss/topic/406748/

Luckily, on Chrome or Edge anyways, if you press Alt, then Alt+Left, it focuses the three dots button on the menu bar and then you can go back.

Originally reported on https://github.com/LLK/scratch-www/issues/6878, but that was in the wrong repository AFAIK

cwillisf commented 2 years ago

Some additional information: I noticed while investigating this that if the input focus is in a text field, for example if you're editing the text in a "think" block, then the alt-left key combo causes the browser to go back as expected.

DNin01 commented 1 year ago

Aha! This is the culprit: https://github.com/scratchfoundation/scratch-gui/blob/0bd773871998e5df34ff0b32c8cd026c57d401a0/src/lib/vm-listener-hoc.jsx#L97-L100 e.preventDefault() was probably used here to stop the arrow keys or space bar from scrolling the page, but it also prevents it from activating the back/forward keyboard shortcuts. All we should need to do is add && !e.altKey, and maybe some other modifier keys to fix other potential keyboard shortcuts.