Skip to content

Support Command shortcuts in Crumble on macOS#1065

Open
GautamNambiar wants to merge 13 commits into
quantumlib:mainfrom
GautamNambiar:crumble-mac-shortcuts
Open

Support Command shortcuts in Crumble on macOS#1065
GautamNambiar wants to merge 13 commits into
quantumlib:mainfrom
GautamNambiar:crumble-mac-shortcuts

Conversation

@GautamNambiar
Copy link
Copy Markdown

@GautamNambiar GautamNambiar commented May 14, 2026

Adds macOS Command-key support for Crumble editing shortcuts, excluding paste.

Changes include:

  • Command+Z / Command+Shift+Z / Command+Y for undo and redo
  • Command+C / Command+X / Command+v for copy/cut/paste
  • Command+Enter as a Mac-friendly insert-layer shortcut
  • Command+Backspace / Command+Delete for deleting the current layer
  • Command-click as an alias for Control-click selection toggling
  • Command-click support for example links
  • Toolbox preview suppression while Command is held
  • Updated shortcut docs and button labels
  • Regenerated embedded Crumble resource

Command shortcuts are handled directly when the key is pressed because, in local macOS testing, routing them through Crumble’s chord preview/finalization flow made shortcuts like Command+Z and Command+Enter unreliable.

Command+V uses the browser paste event instead of directly reading from navigator.clipboard, avoiding clipboard-read permission prompts while preserving the existing Control+V path.

Addresses #651.

I worked with ChatGPT to help understand the code and make edits.

Updated keyboard shortcuts to support the use of macOS command key to substitute for all instances of the control key.
mac users can use command key instead of control key. For Windows keyboard users, since the meta key is the Windows key, this means that the control key can be replaced by the Windows key. (This is a harmless side effect.)
Fixing issues with keydown when pressing cmd
@GautamNambiar
Copy link
Copy Markdown
Author

The main issue that prompted me to make this fix was that ctrl+click on mac usually leads to the equivalent of a right click in Windows. So I had found difficulty with group-selecting two sets of qubits (as a symmetric difference). The PR fixes it.

Comment thread glue/crumble/README.md Outdated
Comment thread glue/crumble/main.js
* @param {!boolean} preview
*/
function pasteTextFromClipboardEvent(text, preview) {
let pastedCircuit = Circuit.fromStimCircuit(text);
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.

This is very similar to pasteFromClipboard. This code should be written once.

Copy link
Copy Markdown
Author

@GautamNambiar GautamNambiar May 18, 2026

Choose a reason for hiding this comment

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

Thanks! This is fixed now. Please also see my reply to the next comment for further clarification.

@DeDuckProject
Copy link
Copy Markdown
Contributor

Description says that Cmd+V behaviour was unchanged, but the code does have it in scope.

Comment thread glue/crumble/main.js
*/
function handleKeyboardEvent(ev) {
async function handleKeyboardEvent(ev) {
if (ev.type === 'keydown' && ev.metaKey) {
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.

Wouldn't these better be right next to the other chord handlers (makeChordHandlers) with meta+z etc.?

Copy link
Copy Markdown
Author

@GautamNambiar GautamNambiar May 18, 2026

Choose a reason for hiding this comment

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

I had originally tried what you suggested: meta+... chord handlers. But on my browsers (chrome and Safari, macOS), doing so, i.e. using the chord preview/finalization flow made shortcuts like cmd+Z and cmd+Enter unreliable. I don't know why, but handling these shortcuts immediately when the key is pressed made them consistent (this was suggested by chatGPT). It seems that for these shortcuts, bypassing the preview system seems to be harmless. Existing ctrl shortcuts still go through Crumble’s chord handler.

So I kept the cmd shortcut handling separate from makeChordHandlers.

cmd+V has one extra difference: it uses the browser paste event to get pasted text, instead of directly calling navigator.clipboard.readText(). This avoided the browser clipboard-read permission prompt I saw during testing.

ctrl+V still gets text using the existing navigator.clipboard.readText() path.

After the pasted text is obtained, cmd+V and ctrl+V now both call the same pasteTextAtFocus helper, so the actual Crumble editing behavior is shared (so the duplication is fixed).

A short comment has been added above the helper explaining why it exists.

I should note that I know very little about web development. I was asking chatGPT, testing, asking again and so on. So, probably there is a cleaner way to do this...

@GautamNambiar
Copy link
Copy Markdown
Author

GautamNambiar commented May 18, 2026

Description says that Cmd+V behaviour was unchanged, but the code does have it in scope.

Sorry, my bad. I initially wanted to separate the fix to cmd +v from everything else (because cmd+v was leading to browser permission prompts to look into the clipboard, and so this had to be treated separately). But I messed up with version control.

Anyway, now, cmd+v is in scope and I have updated the description. Please review again if you get a chance. Thanks!

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.

2 participants