Skip to content

[Codebridge] Added weblab and pythonlab shortcuts for run button, console, and editor #65839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 16, 2025

Conversation

hannahbergam
Copy link
Contributor

@hannahbergam hannahbergam commented May 14, 2025

Adds keyboard shortcuts for the run button (ctrl + 2), the editor (ctrl + 1) and the console output (ctrl + 3) for PythonLab (and the edit shortcut works for Weblab).

I added this in Codebridge so it would work for pythonlab and weblab.

Below is a video! It's a bit hard to follow unless you can see the focus, which I use the shortcuts to move between run button, editor, and output.

This is after hearing from the Maryland School for the Blind kids that they'd like a quicker way to navigate between the most important parts of the page!

I elected to use ctrl + instead of just the letters so that the shortcuts also work from within (and don't interfere with) the text editors (console and workspace editor).

I have a mac, so would appreciate someone testing this on another device!

Screen.Recording.2025-05-14.at.1.22.33.PM.mov

Links

Testing story

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@hannahbergam hannahbergam marked this pull request as ready for review May 14, 2025 20:28
@hannahbergam hannahbergam changed the title Added weblab and pythonlab shortcuts for run button, console, and editor [Codebridge] Added weblab and pythonlab shortcuts for run button, console, and editor May 14, 2025
@hannahbergam hannahbergam requested a review from a team May 14, 2025 20:29
Copy link
Contributor

@sanchitmalhotra126 sanchitmalhotra126 left a comment

Choose a reason for hiding this comment

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

If helpful, here is the original PR that added a run shortcut for legacy labs! #55942
Two things:

  1. I totally misremembered 🤦 - looks like CTRL+Enter is what we wired up for Run (not CTRL+R)
  2. That PR created a KeyHandler util that may be useful here!

@hannahbergam
Copy link
Contributor Author

If helpful, here is the original PR that added a run shortcut for legacy labs! #55942 Two things:

  1. I totally misremembered 🤦 - looks like CTRL+Enter is what we wired up for Run (not CTRL+R)
  2. That PR created a KeyHandler util that may be useful here!

ooo thank you! I'll take a look at this handler! Also, I might stick with R considering the rest of the shortcuts are letters... but definitely open to feedback.

@hannahbergam
Copy link
Contributor Author

hannahbergam commented May 14, 2025

If helpful, here is the original PR that added a run shortcut for legacy labs! #55942 Two things:

  1. I totally misremembered 🤦 - looks like CTRL+Enter is what we wired up for Run (not CTRL+R)
  2. That PR created a KeyHandler util that may be useful here!

ooo thank you! I'll take a look at this handler! Also, I might stick with R considering the rest of the shortcuts are letters... but definitely open to feedback.

@sanchitmalhotra126 How would you feel about me adding a preventDefault() to the keyHandler?

@hannahbergam
Copy link
Contributor Author

If helpful, here is the original PR that added a run shortcut for legacy labs! #55942 Two things:

  1. I totally misremembered 🤦 - looks like CTRL+Enter is what we wired up for Run (not CTRL+R)
  2. That PR created a KeyHandler util that may be useful here!

ooo thank you! I'll take a look at this handler! Also, I might stick with R considering the rest of the shortcuts are letters... but definitely open to feedback.

@sanchitmalhotra126 How would you feel about me adding a preventDefault() to the keyHandler?

mmm actually this seems to interfere with the rest of the keyboard events so I'm not sure there is an easy way to utilize this util in PythonLab. I would also have to register both ctrl and command, which I believe would make it just as many lines changed😅 Alright with you if I maintain the current approach?

@sanchitmalhotra126
Copy link
Contributor

mmm actually this seems to interfere with the rest of the keyboard events so I'm not sure there is an easy way to utilize this util in PythonLab. I would also have to register both ctrl and command, which I believe would make it just as many lines changed😅 Alright with you if I maintain the current approach?

Yep, totally fine!

Copy link
Contributor

@fisher-alice fisher-alice left a comment

Choose a reason for hiding this comment

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

Checked branch locally and works great 🎉! (Unfortunately, I'm also on a macbook.)
Left a handful of suggestions that wouldn't impact functionality. Thanks for being pro-active about this!

// which are preceded by Control (Windows/Linux) or Command (macOS).
// Runs on mount (see empty dependency list).
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could create a re-usable hook like UseWorkspaceKeyboardShortcuts and pass selector names to help readability and coud possibly be used in other labs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to leave this to a future me to refactor if we ever decide to prioritize a more comprehensive approach to keyboard shortcuts here!

@sanchitmalhotra126
Copy link
Contributor

One other question - any concerns with this interfering with the standard browser refresh shortcut (CTRL+R/CMD+R)?

@hannahbergam
Copy link
Contributor Author

One other question - any concerns with this interfering with the standard browser refresh shortcut (CTRL+R/CMD+R)?

Mmmm Okay I can see why this might've resulted in using enter instead of r for run! I'm happy to switch to that instead (and it's also good for consistency).

@hannahbergam hannahbergam merged commit a8c7852 into staging May 16, 2025
6 checks passed
@hannahbergam hannahbergam deleted the hbergam/pythonlab-shortcuts branch May 16, 2025 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants