Skip to content

Add a keyboard shortcut for Run tests - #144

Merged
jserv merged 2 commits into
sysprog21:mainfrom
melonpuff:feat/add-run-test-hotkey
Sep 30, 2026
Merged

jserv merged 2 commits into
sysprog21:mainfrom
melonpuff:feat/add-run-test-hotkey

Conversation

@melonpuff

@melonpuff melonpuff commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cmd+Enter on macOS, or Ctrl+Enter on Windows and Linux, now runs the tests from anywhere on the interview page. The chord is borrowed from LeetCode, where it submits a solution. CodeTrial has no separate submit, so here it presses Run tests.

The shortcut listens on the whole page rather than on the editor, so it still works right after reading the problem or picking a language, without clicking back into the editor first. Other text fields, such as the report's STAR answers and the candidate case inputs, keep the chord for themselves. Only the plain chord counts: Shift or Alt held with it, a press while composing with an IME, and the repeats of a held chord are ignored.

It follows the Run tests button's disabled state, so it never starts a second run or fires while paused. It also does nothing before the media preflight is done or once the interview has ended. The button names the shortcut in a hover tooltip, and in aria-keyshortcuts for screen readers.

Testing

Automated, on 01e1825 (macOS 15):

  • node --test tests/browser/run-shortcut.test.js: 6 passed, 0 skipped. The tests cover:
    • both chords in the editor, with no newline typed
    • a press after a click on the problem takes focus from the editor
    • the media preflight still up
    • an ended interview, with focus back in the editor
    • a second press while a run is in flight
    • a press while the interview is paused

By hand, in Chrome on macOS 15, with the official release binary built from 4874d8d (this branch's base) as the server and --web-dir pointing it at this branch's web/, so the page ran this branch's interview.js:

  • No newline typed when Cmd+Enter is pressed.
  • Cmd+Enter runs the tests from the editor and after a click on the problem.
  • Nothing runs during the preflight, while paused, while composing with an IME (Input Method Editor), or after the interview has ended.
  • The tooltip shows the shortcut on hover.

Refs #131: the shortcut still reaches Run tests when the avatar covers the button. This may serve as a workaround until the overlap is fixed.
Closes #175


Summary by cubic

Cmd+Enter (macOS) and Ctrl+Enter (Windows/Linux) now run the tests from anywhere on the interview page, without clicking back into the editor first. The shortcut follows the Run tests button's disabled state, so it never starts a second run or fires while paused, and does nothing before the media preflight completes or after the interview ends. Only the plain chord works—Shift and Alt are ignored—and presses during IME composition or key repeat are dropped, so holding the chord cannot fire multiple runs. The shortcut prevents Enter's default, never typing a newline into the code or activating a focused button, except in other text fields, which keep the chord for their own line breaks.

The shortcut is now discoverable: the Run tests button shows it in a hover tooltip and announces it via aria-keyshortcuts for screen readers. New browser tests cover both chords in and out of the editor, the preflight, an ended interview, a second press while a run is in flight, and a press while the interview is paused.

Written for commit ab3efb0. Summary will update on new commits.

Review in cubic

@jserv
jserv requested review from ColtenOuO and alanhc September 28, 2026 12:23
Comment thread web/interview.js
Comment thread web/interview.js Outdated
Comment thread web/interview.js
Comment thread web/interview.js
Comment thread tests/browser/run-shortcut.test.js Outdated
Comment thread web/interview.js Outdated
Comment thread web/interview.js Outdated
Comment thread web/interview.js
@jserv

jserv commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

@melonpuff The only reference here is Refs #131, so nothing closes when this merges, and #175 asks for exactly this shortcut down to the same chord (it was filed a day after you opened this, which is why it is not in the body); please end the body with Closes #175 and keep the #131 note where it is, otherwise #175 has to be closed by hand.

@SkyDrive2

Copy link
Copy Markdown

Coming from #175. The page-wide listener and edge-case guards in this PR thoroughly cover what I had envisioned.

Regarding @ColtenOuO's comment on discoverability: in my proposal in #175, I had suggested adding a title attribute to the button in web/interview.html (line 171):

<button id="run-tests" class="run-button" type="button" title="Run tests (Ctrl+Enter / ⌘Enter)">

Perhaps we can also adopt that change here(along with aria-keyshortcuts="Control+Enter Meta+Enter")to provide an immediate visual and accessible cue for candidates?

Aside from the edge cases already highlighted by @jserv and @ColtenOuO, the implementation looks solid!

Comment thread tests/browser/run-shortcut.test.js Outdated

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The shortcut behavior looks good, but could we also expose it on the Run tests button before this closes #175?

#175 proposes a button tooltip, and the current UI otherwise gives candidates no way to discover that the shortcut exists. Adding both a visible/hover hint and the semantic shortcut declaration would complete that part of the issue

Comment thread tests/browser/run-shortcut.test.js
@ColtenOuO

Copy link
Copy Markdown
Collaborator

Perhaps we can also adopt that change here(along with aria-keyshortcuts="Control+Enter Meta+Enter")to provide an immediate visual and accessible cue for candidates?

Yeah, I agree that this properly resolves the issue. While keyboard shortcuts do improve the user experience, we shouldn't assume users will already know about them.

@melonpuff
melonpuff force-pushed the feat/add-run-test-hotkey branch from fb8f0ea to 5073439 Compare September 30, 2026 08:59
@melonpuff

Copy link
Copy Markdown
Contributor Author

Thanks @SkyDrive2 and @ColtenOuO for pointing out the discoverability gap. Fixed in 5073439: the Run tests button now has title="Run tests (Ctrl+Enter / ⌘Enter)", shown on hover, and aria-keyshortcuts="Control+Enter Meta+Enter" for screen readers. The label stays "Run tests", so the toolbar layout is unchanged.

Screenshot from Chrome on macOS 15:
image

@jserv
jserv requested a review from ColtenOuO September 30, 2026 09:17

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please address the feedback from @jserv and me, and resolve the conversation once updated. (It looks like some of them are still unresolved.)

@ColtenOuO

Copy link
Copy Markdown
Collaborator

I think we are almost there.

Could you please squash the minor commits and update the commit message accordingly?

Running the code meant leaving the keyboard for the Run tests button,
which a candidate presses many times in an interview. Cmd+Enter now
presses it from anywhere on the page, and Ctrl+Enter does the same
where there is no Command key, so reading the problem or picking a
language costs no click back into the editor. Other text fields keep
the chord for their own line breaks, and Shift or Alt with it, a
keydown an input method still owns, and the repeats of a held chord
are ignored. The shortcut follows the button's disabled state, so it
never starts a second run or fires while paused, and it does nothing
before the media preflight is done or once the interview has ended,
where the button is still enabled.

The browser tests count runs rather than clicks and cover both chords,
a press from outside the editor, the preflight, an ended interview, a
second press during a run, and a press while paused.
Nothing on the page said the shortcut existed, so a candidate who had
not met the chord elsewhere would never find it. The Run tests button
now names it in a title shown on hover, and carries aria-keyshortcuts
for Control+Enter and Meta+Enter so a screen reader announces it too.
@melonpuff
melonpuff force-pushed the feat/add-run-test-hotkey branch from 01e1825 to ab3efb0 Compare September 30, 2026 18:17

@ColtenOuO ColtenOuO left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working on this!

Let's wait for CI green.

@jserv
jserv merged commit 9fe7cc9 into sysprog21:main Sep 30, 2026
6 checks passed
@jserv

jserv commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Thank @melonpuff for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Ctrl+Enter / Cmd+Enter shortcut to trigger Run tests

4 participants