Skip to content

Preserve heading/title style when splitting blocks#133

Merged
hackerwins merged 1 commit into
mainfrom
feat/preserve-heading-style-on-split
Apr 15, 2026
Merged

Preserve heading/title style when splitting blocks#133
hackerwins merged 1 commit into
mainfrom
feat/preserve-heading-style-on-split

Conversation

@hackerwins

@hackerwins hackerwins commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Paragraph style preservation: Splitting Title/Heading/Subtitle blocks at the beginning or middle now preserves the style on both halves (Google Docs behavior). Splitting at the end resets the new block to paragraph.
  • Empty block height fix: Empty Title/Heading/Subtitle blocks now render with correct line height based on their block type font size instead of falling back to default 11pt.
  • Yorkie tree path resolution: editByPath paths are now computed from the actual Yorkie tree inline structure instead of the cache, preventing unacceptable path errors when normalizeInlines merges inlines that remain separate in the Yorkie tree after split/merge operations.

Test plan

  • Unit tests for split style preservation (6 new tests in document.test.ts)
  • Unit tests for empty block height (3 new tests in layout.test.ts)
  • All existing tests pass (pnpm verify:fast + frontend tests)
  • Manual smoke test: Title block split at beginning/middle/end
  • Manual smoke test: consecutive Enter presses with merge (backspace) cycles

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

Bug Fixes

  • Fixed block type and formatting preservation when editing and splitting headings, titles, and subtitles
  • Improved font sizing accuracy for empty styled blocks
  • Enhanced text editing reliability and consistency when inserting, deleting, and splitting content

…ior)

When pressing Enter in a Title/Heading/Subtitle block, preserve the
block style on both halves unless splitting at the end (where the new
block resets to paragraph). This matches Google Docs behavior.

Also fixes two related bugs:
- Empty title/heading blocks now use the correct font size for height
  calculation instead of falling back to the default 11pt.
- Yorkie tree path resolution now reads the actual tree inline
  structure instead of the cache, preventing "unacceptable path"
  errors when cache inlines (normalized) diverge from Yorkie tree
  inlines (separate nodes after split/merge).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 15ce0b39-53c8-4876-aaa9-d261087a0293

📥 Commits

Reviewing files that changed from the base of the PR and between 80e6c06 and 0f24164.

📒 Files selected for processing (6)
  • packages/docs/src/model/document.ts
  • packages/docs/src/store/block-helpers.ts
  • packages/docs/src/view/layout.ts
  • packages/docs/test/model/document.test.ts
  • packages/docs/test/view/layout.test.ts
  • packages/frontend/src/app/docs/yorkie-doc-store.ts

📝 Walkthrough

Walkthrough

The changes extend block type and style preservation when splitting document blocks. Splitting title, subtitle, or heading blocks mid-text now retains their original type rather than defaulting to paragraph. Font size fallback logic for empty blocks and heading level preservation on splits are added across model, store, view, and frontend layers.

Changes

Cohort / File(s) Summary
Block Split Type Preservation
packages/docs/src/model/document.ts, packages/docs/src/store/block-helpers.ts
Extended splitBlock to preserve title, subtitle, and heading types when split offset is before block text end. Updated applySplitBlock to conditionally preserve headingLevel on the after-block only when newBlockType is 'heading'.
Test Coverage for Type/Style Preservation
packages/docs/test/model/document.test.ts, packages/docs/test/view/layout.test.ts
Added test cases verifying type/headingLevel preservation across split offsets for heading, title, and subtitle blocks. Added empty-block-height tests to ensure layout assigns identical heights for blocks with empty vs. non-empty content.
Font Size Fallback for Empty Blocks
packages/docs/src/view/layout.ts
Updated getLineMaxFontSizePx to compute fallback font size from block type defaults when no run font sizes exist, providing type-specific defaults for title, subtitle, and heading blocks.
Yorkie Tree Offset Resolution
packages/frontend/src/app/docs/yorkie-doc-store.ts
Added resolveTreeOffset method to map cached block offsets to actual Yorkie tree positions. Refactored insertText, deleteText, and splitBlock to use tree-based offset resolution. Extended split styling to preserve headingLevel for heading blocks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 When blocks split in two, preserving their dress,
Headings keep their level, no need to confess,
Empty lines now know their font from the start,
Type preservation—a rabbit's sweet art! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Preserve heading/title style when splitting blocks' directly summarizes the main change: extending block split logic to preserve heading, title, and subtitle styles when splitting at certain offsets, which is clearly demonstrated across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/preserve-heading-style-on-split

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 and usage tips.

@github-actions

github-actions Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Verification: verify:self

Result: ✅ PASS in 120.7s

Lane Status Duration
sheets:build ✅ pass 13.6s
docs:build ✅ pass 8.1s
verify:fast ✅ pass 60.9s
frontend:build ✅ pass 16.0s
verify:frontend:chunks ✅ pass 0.3s
backend:build ✅ pass 4.9s
cli:build ✅ pass 1.8s
verify:entropy ✅ pass 15.2s

Verification: verify:integration

Result: ✅ PASS

@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@hackerwins
hackerwins merged commit 8811f7b into main Apr 15, 2026
4 checks passed
@hackerwins
hackerwins deleted the feat/preserve-heading-style-on-split branch April 15, 2026 22:41
@hackerwins hackerwins mentioned this pull request Apr 19, 2026
1 task
@coderabbitai coderabbitai Bot mentioned this pull request Apr 22, 2026
3 tasks
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.

1 participant