feat: add markdown formatting keyboard shortcuts - #6255
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughAdds shared formatting command dispatch and five memo-editor shortcuts: bold, italic, strikethrough, code, and link. The new keymap runs before the default keymap and prevents browser defaults. Link insertion now places the cursor before the closing parenthesis when the URL is empty. Tests cover shortcut handling, bold toggling, and link cursor placement. Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change adds localized formatting shortcuts and improves empty-link cursor placement without affecting services, permissions, persistence, or deployment behavior. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
Greptile SummaryThe PR adds CodeMirror keyboard shortcuts for five inline Markdown formatting commands and routes them through the same command implementation used by the toolbar. It also adjusts URL-less link insertion so the cursor is positioned inside the destination parentheses.
Confidence Score: 5/5The PR appears safe to merge, with no concrete behavioral, security, or compatibility defects identified. The shortcuts are ordered ahead of default CodeMirror bindings, delegate to the established formatting implementation, and preserve editor update propagation; the changed link offset correctly targets the boundary between the destination parentheses.
|
| Filename | Overview |
|---|---|
| web/src/components/MemoEditor/Editor/extensions.ts | Wires the formatting keymap ahead of the default keymap without conflicting with the existing submit, Tab, or Escape bindings. |
| web/src/components/MemoEditor/Editor/formatting.ts | Extracts formatting dispatch into a shared function and correctly places the cursor inside empty link-destination parentheses. |
| web/src/components/MemoEditor/Editor/formattingKeymap.ts | Defines conventional modifier shortcuts that invoke existing formatting commands and suppress competing browser defaults. |
| web/tests/memo-editor-formatting-keymap.test.ts | Covers binding declarations, shared bold-toggle behavior, and both branches of link cursor placement, though not end-to-end keyboard-event dispatch. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
K[Formatting keyboard shortcut] --> M[CodeMirror formatting keymap]
T[Toolbar action] --> C[Formatting controller]
M --> R[runFormattingCommand]
C --> R
R --> D[Dispatch document and selection update]
D --> U[Editor update listener]
U --> S[Refresh formatting state]
Reviews (1): Last reviewed commit: "feat: add markdown formatting keyboard s..." | Re-trigger Greptile
Closes #6253
Adds keyboard shortcuts for the existing formatting commands: Mod-B (bold), Mod-I (italic), Mod-Shift-X (strikethrough), Mod-E (inline code), Mod-K (link), matching Obsidian/Notion conventions.
Mod-is Cmd on macOS and Ctrl elsewhere.The keymap dispatches the same
runFormattingCommandthe toolbar uses, so toggle/strip behavior can never diverge between mouse and keyboard. Only inline marks and link are bound: block commands (lists, headings, code block) have no widely shared convention, and unused bindings would shadow browser/OS shortcuts for no gain.Also: inserting a link without a URL now places the cursor between the parens (
[label](|)), ready to type the target; with a URL supplied the cursor still lands after the finished link.Changes
Editor/formatting.ts: extracted the controller'srunbody into an exportedrunFormattingCommand(controller delegates to it) + the link cursor placementEditor/formattingKeymap.ts(new): the five bindings, each withpreventDefaultso browser chords like Ctrl-K never fireEditor/extensions.ts: keymap wired abovedefaultKeymapso the formatting chords wintests/memo-editor-formatting-keymap.test.ts(new): chord table, toolbar parity, link cursor placementTesting
pnpm run lint(tsc + biome) clean