fix(text editor): make the code block toggle context-aware and preserve line breaks - #4227
fix(text editor): make the code block toggle context-aware and preserve line breaks#4227john-traas wants to merge 3 commits into
Conversation
|
Warning Review limit reached
Next review available in: 16 minutes Limit details: You’ve used all 1 included review currently available under your plan. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
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 |
|
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4227/ |
There was a problem hiding this comment.
Pull request overview
This PR rebuilds the text editor’s code block command to be selection-context aware (matching the list-command “ladder” approach) and to preserve line breaks when toggling code blocks off, aligning toolbar visibility (allowed()) with actual command applicability.
Changes:
- Added
code-block-utils.tsto classify selection context, detect non-convertible selections, toggle-off by splitting into one paragraph per line, and unify multi-block/mixed selections into a single code block. - Replaced the legacy code block toggle wiring with
createCodeBlockCommand, sharing applicability rules between the command body andallowed()so toolbar and keymap behavior match. - Suppressed
exampleSetup’s rawShift-Ctrl-\code block binding soMod-Shift-Cis the single supported shortcut path.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/text-editor/prosemirror-adapter/menu/menu-commands.ts | Introduces createCodeBlockCommand and wires it into the command mapping so keymap/toolbar share applicability rules. |
| src/components/text-editor/prosemirror-adapter/menu/menu-command-utils/code-block-utils.ts | Implements context resolution, convertibility guard, toggle-off (split per line), and unify-to-single-code-block transforms. |
| src/components/text-editor/prosemirror-adapter/menu/menu-code-block-commands.spec.ts | Adds standalone-schema unit tests covering the behavior matrix and no-dispatch decline cases. |
| src/components/text-editor/prosemirror-adapter/editor-keymap.e2e.ts | Adds mounted-view coverage for multi-block merge, toggle-off split, and the unbound Shift-Ctrl-\ case. |
| src/components/text-editor/prosemirror-adapter/editor-config.ts | Disables exampleSetup’s Shift-Ctrl-\ binding via mapKeys to avoid bypassing the command ladder. |
| src/components/text-editor/prosemirror-adapter/editor-commands.spec.ts | Extends real-schema tests to cover merge/unify/split behaviors and list-touch decline + allowed() behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
b4b10fc to
337cf7f
Compare
26c805e to
e1db1d6
Compare
Summary
Rebuilds the code block command on the selection-context ladder introduced for the list commands in #4222, per #4225.
code-block-utils.ts:resolveCodeBlockContext(in-code/no-code/mixed), a convertibility guard (paragraphs, headings and code blocks convert; blockquotes are transparent; lists, tables, rules and other nodes decline), a toggle-off transform that splits each code block on\ninto one paragraph per line, and a unify transform that merges multi-block and mixed selections into a single code block.createCodeBlockCommand: the command body andallowed()share the same applicability rules, so the toolbar button is hidden whenever the command cannot apply — no more enabled-looking button that silently does nothing.Shift-Ctrl-\binding is suppressed viamapKeys, leavingMod-Shift-C(which routes through the command) as the single code block shortcut.Fixes #3179
Fixes #3314
Closes #4225
Behavior matrix
allowed()Tests
menu-code-block-commands.spec.ts: 23 behavior-matrix cases on a standalone schema, including no-dispatch assertions for every decline.editor-commands.spec.ts: real-schema toggle-off, mixed unify, and list-decline cases.editor-keymap.e2e.ts: mounted-view coverage for multi-block merge, toggle-off split, and the unboundShift-Ctrl-\.Notes
text-editor-list-handling; will be retargeted tomainonce that branch lands.🤖 Generated with Claude Code