fix(core): show formatting toolbar when selection spans a code block and other content#2899
fix(core): show formatting toolbar when selection spans a code block and other content#2899RIDAM7 wants to merge 1 commit into
Conversation
…lar content The formatting toolbar was hidden whenever the selection contained any code node, so a selection spanning both a code block and regular text hid it entirely even though the non-code content is formattable. It now only stays hidden when the selection is entirely within code. Fixes TypeCellOS#2865
|
@RIDAM7 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⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe formatting toolbar visibility logic is extracted into an exported transaction helper. It hides the toolbar for empty, non-text, and code-only selections while showing it for regular and mixed selections. New editor-backed tests cover these cases. ChangesFormatting toolbar visibility
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Problem
The formatting toolbar disappears whenever a selection contains a code block, even when the selection also covers regular formattable text. So selecting across a paragraph and a code block (or any multi-block selection that includes code) hides the toolbar entirely, even though there's non-code content you could still format. (#2865)
Fix
The visibility check hid the toolbar whenever the selected content contained any node with a code spec. It now only hides when the selection is entirely within code, i.e. it spans a code node but has no other formattable inline content. A selection that mixes a code block with regular content keeps the toolbar.
I also pulled the predicate out into an exported
formattingToolbarShouldShow(tr)function so it can be unit tested directly.Testing
Added
packages/core/src/extensions/FormattingToolbar/FormattingToolbar.test.tscovering four cases: empty selection, a selection over regular content, a selection entirely within code, and a selection spanning both a code block and regular content (the bug). Confirmed the new test fails on the old logic and passes with the fix. Full core suite passes (493 tests) andtsc --noEmiton core is clean.Fixes #2865
AI disclosure
Claude (Anthropic) assisted in diagnosing the root cause and drafting the fix.
Summary by CodeRabbit