Skip to content

Fix: let modifier-key shortcuts (Cmd+-, Ctrl++ etc.) pass through to the browser#124

Open
paperboyo wants to merge 3 commits into
mainfrom
mk/fix-modifier-key-swallowing
Open

Fix: let modifier-key shortcuts (Cmd+-, Ctrl++ etc.) pass through to the browser#124
paperboyo wants to merge 3 commits into
mainfrom
mk/fix-modifier-key-swallowing

Conversation

@paperboyo

@paperboyo paperboyo commented May 10, 2026

Copy link
Copy Markdown

[this is not me, this is Claude, I verified in Kupua it fixes the issue affecting Grid and sandbox too, but 🤖s, yeah]

handleKeyDown was unconditionally intercepting '+' and '-' keypresses, including when Cmd or Ctrl was held. This caused browser shortcut Cmd+- (zoom out) to be swallowed, inserting a negated chip instead.

What does this change?

The fix adds an early return in handleKeyDown for + and - when metaKey or ctrlKey is held, so Cmd+- / Cmd++ / Ctrl+- pass through to the browser as zoom shortcuts rather than triggering chip creation. Other shortcut combos are unaffected.

Fixes #118.

How has this change been tested?

Local build was linked to Kupua and I pressed Cmd+- while in the searchbox. Robot also ran some buns.

How can we measure success?

I know everything about “success”. It’s that thing, which, then… and… driveway. Driveway is a success.

Have we considered potential risks?

No, wait, we didn’t, now, did we? [EDIT: but we have added tests and have tested it in the sandbox too]

Images

Images? Oh, yeah. I liked this one I found today:

Economist Ads

Accessibility

… the browser

handleKeyDown was unconditionally intercepting '+' and '-' keypresses,
including when Cmd or Ctrl was held. This caused browser shortcuts like
Cmd+- (zoom out) and Cmd+= (zoom in) to be swallowed, inserting a
negated/positive chip instead.

The fix adds an early return at the top of handleKeyDown when metaKey or
ctrlKey is true. None of the keys handled in this function (+, -, :,
Escape, Delete, Backspace, Enter, arrows) have legitimate Cmd/Ctrl
meanings within CQL — ProseMirror's keymap plugin handles Mod-bindings
(Mod-a, Mod-z, Ctrl-a, Ctrl-e) separately and fires before
handleKeyDown.

Fixes #118.
@github-actions

github-actions Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

@paperboyo paperboyo added the fix Departmental tracking: fix label May 10, 2026
@paperboyo paperboyo requested a review from Copilot May 15, 2026 23:20

Copilot AI left a comment

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.

Pull request overview

Fixes browser/OS shortcuts (e.g. Cmd+-, Cmd+=) being swallowed by the CQL editor and inserting polarity chips instead of zooming. The fix is a one-line early return in handleKeyDown when metaKey or ctrlKey is held.

Changes:

  • In handleKeyDown, return false early when a modifier (Cmd/Ctrl) is pressed so the browser/ProseMirror keymap can handle the event.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The original guard returned false for *any* metaKey or ctrlKey combo,
which silently broke Cmd+Backspace (chip deletion) and Cmd+Delete, since
those never reached the switch cases that call removeChipAdjacentToSelection.

Narrow the early return to only the keys that need protecting:

  if ((metaKey || ctrlKey) && (key === "+" || key === "-")) return false;

This lets Cmd+- and Cmd++ pass through to the browser (zoom shortcuts)
while leaving Cmd+Backspace, Cmd+Delete, and all other modifier combos
falling through to the existing switch handlers as before.
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Four tests covering both sides of the fix:

Chip creation (modifier keys do not trigger chip creation):
- Cmd+- does not create a chip
- Cmd++ does not create a chip
- Ctrl+- does not create a chip
These fail against the original code (no guard) and pass with the fix.

Regression guard (deletion):
- Cmd+Backspace still removes a chip adjacent to the cursor
This fails against the overly-broad guard (metaKey || ctrlKey) that was
narrowed in the previous commit, and passes with the correct narrow guard.

Together the four tests pin down the exact shape of the fix: only + and -
are exempted for modifier combos; all other keys (Backspace, Delete, etc.)
continue to be handled as normal.

Uses fireEvent.keyDown for the Cmd+Backspace test since editor.shortcut()
does not propagate metaKey correctly through ProseMirror's event system
in the test environment.
@paperboyo

Copy link
Copy Markdown
Author

Now narrowed and with tests.

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

Labels

fix Departmental tracking: fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cmd+[minus key] adds negated chip...

2 participants