Skip to content

feat: Add keyboard shortcut to perform an action on the currently focused element#9673

Merged
gonfunko merged 6 commits intov13from
lights-camera-action
Apr 8, 2026
Merged

feat: Add keyboard shortcut to perform an action on the currently focused element#9673
gonfunko merged 6 commits intov13from
lights-camera-action

Conversation

@gonfunko
Copy link
Copy Markdown
Contributor

@gonfunko gonfunko commented Apr 1, 2026

The basics

The details

Resolves

Proposed Changes

This PR backports the Enter keyboard shortcut from the keyboard-experimentation repo that performs an action on the currently focused element. It adds an optional performAction() method to IFocusableNode which may be adopted by classes to gain support for Enter acting upon them.

@gonfunko gonfunko requested a review from a team as a code owner April 1, 2026 15:23
@gonfunko gonfunko requested a review from mikeharv April 1, 2026 15:23
@github-actions github-actions bot added the PR: feature Adds a feature label Apr 1, 2026
Copy link
Copy Markdown
Contributor

@mikeharv mikeharv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks for your patience with my questions as some of this code is still somewhat new to me.

* @param workspace The workspace.
*/
export function showHelpHint(workspace: WorkspaceSvg) {
const shortcut = getShortActionShortcut('list_shortcuts');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle the potential case where shortcut is an empty string? I think it's possible that the shortcut could have been unregistered which would lead to a help prompt with a nonsensical message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a possibility, I'm not sure how we might helpfully handle it though. End users wouldn't be able to do anything about it, I suppose we could just not show the toast? Or did you have something else in mind?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's reasonable that if the shortcut isn't available because it was unregistered, we could just return early and not show the toast. No toast is better than one that says "Press for help on keyboard controls". The only other option I can think of would be a fallback string that just says "invalid action" or something if we don't have a shortcut to suggest for help.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an early return in that case. I also disabled the test as it now fails since the shortcut to show the list of shortcuts doesn't yet exist.

Blockly.Msg.KEYBOARD_NAV_CUT_HINT = 'Cut. Press %1 to paste.'; No newline at end of file
Blockly.Msg.KEYBOARD_NAV_CUT_HINT = 'Cut. Press %1 to paste.';
/** @type {string} */
/// Message shown when a user presses Enter with a navigable block focused.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will translators need any more context? For example, is it still the right arrow key on LTR workspaces? (Genuine question I don't know the answer to.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're OK, ideally this would interpolate the actually-bound shortcut like some of the others but that's something we can address later I think.

@gonfunko gonfunko force-pushed the lights-camera-action branch from c9dbb5b to 44a6acc Compare April 7, 2026 21:26
@gonfunko gonfunko requested a review from mikeharv April 8, 2026 16:14
Copy link
Copy Markdown
Contributor

@mikeharv mikeharv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for answering all of my questions. I think my biggest concern is the possibility of creating a toast with a broken/incomplete message if the shortcut has gone missing. This is hopefully more of an edge, but perhaps worth tracking with a new issue so we can remember to solve it at some point.

* @param workspace The workspace.
*/
export function showHelpHint(workspace: WorkspaceSvg) {
const shortcut = getShortActionShortcut('list_shortcuts');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's reasonable that if the shortcut isn't available because it was unregistered, we could just return early and not show the toast. No toast is better than one that says "Press for help on keyboard controls". The only other option I can think of would be a fallback string that just says "invalid action" or something if we don't have a shortcut to suggest for help.

@gonfunko gonfunko merged commit 41319ba into v13 Apr 8, 2026
4 checks passed
@gonfunko gonfunko deleted the lights-camera-action branch April 8, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: feature Adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants