Skip to content

fix(core): show formatting toolbar when selection spans a code block and other content#2899

Open
RIDAM7 wants to merge 1 commit into
TypeCellOS:mainfrom
RIDAM7:fix/2865-formatting-toolbar-code-block
Open

fix(core): show formatting toolbar when selection spans a code block and other content#2899
RIDAM7 wants to merge 1 commit into
TypeCellOS:mainfrom
RIDAM7:fix/2865-formatting-toolbar-code-block

Conversation

@RIDAM7

@RIDAM7 RIDAM7 commented Jul 19, 2026

Copy link
Copy Markdown

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.ts covering 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) and tsc --noEmit on core is clean.

Fixes #2865

AI disclosure

Claude (Anthropic) assisted in diagnosing the root cause and drafting the fix.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed formatting toolbar visibility when selections span both code blocks and regular text.
    • The toolbar now remains available when a selection includes formattable content alongside code.
    • The toolbar stays hidden for selections containing only code or an empty selection.

…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
@vercel

vercel Bot commented Jul 19, 2026

Copy link
Copy Markdown

@RIDAM7 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 Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 87787a4d-895f-4f36-9edc-bf93f2da74c4

📥 Commits

Reviewing files that changed from the base of the PR and between bf0ff0c and ff72ba5.

📒 Files selected for processing (2)
  • packages/core/src/extensions/FormattingToolbar/FormattingToolbar.test.ts
  • packages/core/src/extensions/FormattingToolbar/FormattingToolbar.ts

📝 Walkthrough

Walkthrough

The 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.

Changes

Formatting toolbar visibility

Layer / File(s) Summary
Selection visibility helper and extension wiring
packages/core/src/extensions/FormattingToolbar/FormattingToolbar.ts
Exports formattingToolbarShouldShow, applies code-only selection handling, and delegates the extension callback to the helper.
Editor-backed visibility tests
packages/core/src/extensions/FormattingToolbar/FormattingToolbar.test.ts
Adds lifecycle setup and assertions for empty, regular, code-only, and mixed selections.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

I’m a rabbit with a toolbar bright,
Code and prose now share the light.
Empty hops stay hidden from view,
Mixed selections shine anew.
Tests nibble each case just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers the problem, fix, and testing, but misses most required template sections like Summary, Rationale, Changes, Impact, Checklist, and Screenshots. Reformat the description to match the template and add the missing sections, especially Summary, Rationale, Changes, Impact, Checklist, and Screenshots/Video.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main behavior change in the formatting toolbar visibility logic.
Linked Issues check ✅ Passed The implementation and tests address #2865 by keeping the toolbar visible for mixed code and non-code selections.
Out of Scope Changes check ✅ Passed The changes stay focused on formatting toolbar visibility logic and related tests, with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

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.

Toolbar is not displayed when code block in selection

1 participant