feat: Hide trailing block when editor is read-only (BLO-843)#2724
feat: Hide trailing block when editor is read-only (BLO-843)#2724matthewlipski wants to merge 1 commit intomainfrom
Conversation
…en editor is read-only
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR adds trailing block visibility control by implementing a ProseMirror decoration that marks the trailing empty block and then hiding it via CSS when the editor is in read-only mode, resolving the issue of extra empty blocks appearing in read-only editors. ChangesTrailing Block Visibility Control
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/extensions/TrailingNode/TrailingNode.ts`:
- Around line 40-47: The decorator is currently inferring trailing blocks by
structure and hides any final empty block (using the bn-trailing-block class) —
instead, change the logic in
packages/core/src/extensions/TrailingNode/TrailingNode.ts (the code around
lastBlockContainer / lastBlockContent and the other similar check at lines
~51-55) to only decorate blocks that were appended by the plugin: add and read a
plugin-scoped marker (plugin state/meta or transaction meta) when the plugin
appends a node, and use that marker to gate applying bn-trailing-block in the
decorate function (or whichever function returns decorations), so only nodes
with the plugin append flag get the class while user-authored empty final
paragraphs remain visible.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4806afe8-3074-474f-9005-746fdff85789
📒 Files selected for processing (2)
packages/core/src/editor/editor.csspackages/core/src/extensions/TrailingNode/TrailingNode.ts
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@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
commit: |
Summary
This PR hides the extra block created if the editor
trailingBlockoption is set to true or left undefined, when the edidor is read-only.The block is hidden as opposed to being outright removed to avoid triggering content changes, which is a concern especially in the context of collaboration.
Closes #462
Rationale
The trailing block is pretty useless when read-only - it's whole point is to improve UX when the editor is interactive.
Changes
TrailingNodeExtensionto set.bn-trailing-blockCSS class on trailing block.Impact
N/A
Testing
N/A
Screenshots/Video
Checklist
Additional Notes
N/A
Summary by CodeRabbit