Skip to content

fix(core): register the Mod-Alt-c code block shortcut - #3242

Merged
nperez0111 merged 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/3211-code-block-shortcut
Oct 23, 2026
Merged

nperez0111 merged 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/3211-code-block-shortcut

Conversation

@adarshsm

@adarshsm adarshsm commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #3211.

The "Code Block" item in the default slash menu shows Mod-Alt-c (Ctrl+Alt+C / ⌘+Alt+C) as its shortcut, but pressing it did nothing. This PR registers the shortcut, so it turns the current block into a code block like the other badged shortcuts do.

Rationale

The badge is set in getDefaultSlashMenuItems.ts, and every other badge in that menu has a matching handler in its block spec (Mod-Alt-0 paragraph, Mod-Alt-<level> heading, Mod-Shift-6..9 lists, and Mod-Alt-q quote, which has a handler but no badge). The code block's CodeKeyboardShortcutsExtension only handled Delete, Tab, Enter and Shift-Enter, so Mod-Alt-c fell through.

The issue suggests either adding the handler or dropping the badge. I went with the handler because the badge has been advertising it, and the reporter (XWiki) already patches it in this way downstream.

Changes

  • CodeKeyboardShortcutsExtension.ts: add a Mod-Alt-c handler, modelled on the quote block's Mod-Alt-q. If the block at the cursor has inline content, it's updated to the code block type with default props (so the default language applies). Otherwise the handler returns false.

Impact

  • Converting goes through updateBlock, which already keeps the text and drops formatting the plain-content code block can't hold (e.g. bold).
  • Blocks without inline content (images, tables, code blocks) are left alone.
  • Nothing changes for editors without a code block, since the shortcut lives in the code block spec's extension.

Testing

  • New Code block keyboard shortcut cases in packages/core/src/blocks/Code/block.test.ts. The existing pressKey helper there now takes optional modifier flags.
    • Mod-Alt-c in a paragraph containing const + bold x turns it into a codeBlock with the same id, the default text language and the plain text const x.
    • Mod-Alt-c with the cursor on an image block leaves it an image.
  • Without the handler, the first case fails (expected 'paragraph' to be 'codeBlock'). With it, all 21 tests in the file pass.
  • @blocknote/core suite: the code block, keyboard shortcut and slash menu tests pass. The only failures are the src/y/** / Versioning suites, which fail the same way on main in my local checkout because of a stale @y/y install, unrelated to this change.
  • vp lint and vp fmt --check are clean on the touched files.

Screenshots/Video

n/a

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature (n/a: the shortcut was already shown in the slash menu)

Additional Notes

n/a

Summary by CodeRabbit

  • New Features
    • Added the Ctrl-Alt-C keyboard shortcut to convert blocks with inline content into text code blocks, preserving their existing text and identity.
  • Bug Fixes
    • The shortcut no longer changes blocks that do not support inline content.

The slash menu shows Mod-Alt-c as the "Code Block" shortcut, but no
block registered a handler for it, so pressing it did nothing. Add it to
the code block's keyboard shortcuts, mirroring the quote block's
Mod-Alt-q: blocks with inline content are turned into a code block.

Closes TypeCellOS#3211
@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@adarshsm is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e365ede-ab05-47a4-bc03-2c44e5214f0d
📥 Commits

Reviewing files that changed from the base of the PR and between 45d07d3 and eeadc25.

📒 Files selected for processing: 2
  • packages/core/src/blocks/Code/block.test.ts
  • packages/core/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The code block extension now handles the Mod-Alt-c shortcut for blocks with inline content. Tests check that conversion preserves the block ID and text, and that a block without inline content remains unchanged.

Changes: Code block shortcut

Layer / File(s) Summary
Register and test the shortcut
packages/core/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts, packages/core/src/blocks/Code/block.test.ts
The Mod-Alt-c shortcut converts blocks with inline content to code blocks. Tests verify the converted block retains its ID and text, and that an image block remains unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: nperez0111

Merge Risk: ⚪ Minimal · up to eeadc

The shortcut addresses the missing Code Block action, and no actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: registering the Mod-Alt-c code block shortcut.
Description check Passed The description covers the summary, rationale, changes, impact, testing, checklist, and additional notes. It identifies the documentation item as not applicable and reports the relevant test and lint …
Linked Issues check Passed Issue #3211 asks that Mod-Alt-c convert a block with inline content into a code block, or that the badge be removed. The PR takes the first option. The diff for CodeKeyboardShortcutsExtension.ts adds …
Out of Scope Changes check Passed The changed files are CodeKeyboardShortcutsExtension.ts and Code/block.test.ts. The extension change implements the requested Mod-Alt-c behavior for #3211. The test change adds coverage for that behav…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Full details: Description check

Explanation

The description covers the summary, rationale, changes, impact, testing, checklist, and additional notes. It identifies the documentation item as not applicable and reports the relevant test and lint results.

Full details: Linked Issues check

Explanation

Issue #3211 asks that Mod-Alt-c convert a block with inline content into a code block, or that the badge be removed. The PR takes the first option. The diff for CodeKeyboardShortcutsExtension.ts adds a "Mod-Alt-c" keyboard shortcut. It checks that the cursor block's schema content is "inline". If so, it calls editor.updateBlock with type blockType and props {}, then returns true. Otherwise it returns false. This matches the Mod-Alt-q handler in Quote/block.ts, which the issue cites as the reference. The new tests in block.test.ts cover both requested behaviors. One test converts a paragraph with bold text into a codeBlock with the same id, default language "text", and plain text "const x". The other test confirms an image block keeps its type. The tests were not executed during this review. The PASS rests on the source diff and the test diff. The code block's Delete, Tab, Enter, Shift-Enter and input rule behavior are unchanged.

Full details: Out of Scope Changes check

Explanation

The changed files are CodeKeyboardShortcutsExtension.ts and Code/block.test.ts. The extension change implements the requested Mod-Alt-c behavior for #3211. The test change adds coverage for that behavior. The pressKey helper gains an optional modifiers parameter, which only the new tests use. No unrelated files or behavior changes appear in the reviewed diffs. The PR description states that the slash menu badge and other block specs are not changed. The PR description also reports test-suite failures in src/y/** and Versioning on main. Those failures are outside this diff, and no evidence links them to these changes.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit taps the shortcut key,
Inline words become code for me.
The block keeps its ID in place,
Its text stays put, unchanged in case.
An image stays just as it was,
Then hops away without a pause.

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@3242

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@3242

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@3242

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3242

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@3242

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3242

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@3242

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@3242

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@3242

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@3242

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@3242

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@3242

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@3242

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@3242

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@3242

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/@blocknote/xl-typst-exporter@3242

commit: eeadc25

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
blocknote Ready Ready Preview Oct 23, 2026 8:15am UTC

Request Review

@nperez0111

Copy link
Copy Markdown
Contributor

Thanks @adarshsm this is easy to approve

@nperez0111
nperez0111 merged commit ff32ef6 into TypeCellOS:main Oct 23, 2026
30 of 31 checks passed

This branch was successfully deployed

1 active deployment
Preview – blocknote — eeadc252 Deployed Oct 23, 2026 by vercel[bot]
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.

Slash menu shows Ctrl+Alt+C (Mod-Alt-c) for "Code Block", but the shortcut is not registered

2 participants