Skip to content

Keyboard shortcuts handled with the wrong scope #9101

@microbit-robert

Description

@microbit-robert

Check for duplicates

  • I have searched for similar issues before opening a new one.

Description

There is a keydown listener on the widget div. When we use arrow keys, this listener is triggered. The listener checks to see if the element is a text input or similar and ignores the event if that's the case. Otherwise, the keydown event is passed to the shortcut listener. The shortcut listener attempts to handle the keydown event, and the scope is the currently focused node. This code ignores whether anything has taken ephemeral focus. The focused node is the last field that was focused before the field editor was opened. Therefore, arrow keys move the cursor around the workspace in the background. This is problematic for a complex field editor in MakeCode that uses the widget div.

This doesn't currently happen with dropdown divs, but this is due to another bug where the keydown listener is removed from the dropdown div and not reinstated. I think that when this PR goes in, regular dropdown fields will also exhibit this problem.

I think a possible fix for this that the call to getFocusedNode here must take into account ephemeral focus.

Reproduction steps

The easiest way to reproduce this is probably to run the blockly-keyboard-experimentation repo locally with a linked Blockly repo that has the code changes in #9085 checked out.

You can then:

  • add a show icon block
  • navigate to the icon field with keyboard
  • hit 'Enter' to open the field editor
  • move the cursor on the workspace in the background with the left and right arrow buttons (minor visible change for the first move, invisible after that)
  • hit 'Enter' again to trigger an action whether the cursor now is

See video below for an example of this.

Stack trace

Screenshots

Screen.Recording.2025-05-27.at.16.36.59.mov

Browsers

No response

Metadata

Metadata

Assignees

Labels

injectionissue: bugDescribes why the code or behaviour is wrong

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions