Repository navigation
fix(core): register the Mod-Alt-c code block shortcut - #3242
Conversation
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
|
@adarshsm is attempting to deploy a commit to the TypeCell Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/diagram-block
@blocknote/mantine
@blocknote/math-block
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
@blocknote/xl-typst-exporter
commit: |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thanks @adarshsm this is easy to approve |
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-0paragraph,Mod-Alt-<level>heading,Mod-Shift-6..9lists, andMod-Alt-qquote, which has a handler but no badge). The code block'sCodeKeyboardShortcutsExtensiononly handledDelete,Tab,EnterandShift-Enter, soMod-Alt-cfell 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 aMod-Alt-chandler, modelled on the quote block'sMod-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 returnsfalse.Impact
updateBlock, which already keeps the text and drops formatting the plain-content code block can't hold (e.g. bold).Testing
Code block keyboard shortcutcases inpackages/core/src/blocks/Code/block.test.ts. The existingpressKeyhelper there now takes optional modifier flags.Mod-Alt-cin a paragraph containingconst+ boldxturns it into acodeBlockwith the same id, the defaulttextlanguage and the plain textconst x.Mod-Alt-cwith the cursor on an image block leaves it an image.expected 'paragraph' to be 'codeBlock'). With it, all 21 tests in the file pass.@blocknote/coresuite: the code block, keyboard shortcut and slash menu tests pass. The only failures are thesrc/y/**/ Versioning suites, which fail the same way onmainin my local checkout because of a stale@y/yinstall, unrelated to this change.vp lintandvp fmt --checkare clean on the touched files.Screenshots/Video
n/a
Checklist
Additional Notes
n/a
Summary by CodeRabbit