Skip to content

Word-wrap-aware automatic row height (#1969) - #2049

Merged
aiongg merged 1 commit into
storytold:mainfrom
bfenty:fix/wrap-row-height-1969
Oct 22, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
bfenty:fix/wrap-row-height-1969

Conversation

@bfenty

@bfenty bfenty commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem (#1969)

auto_row_height counted a wrapped cell's lines as total-text-width ÷ column-width, as if words could split anywhere. The grid word-wraps whole words (egui LayoutJob), so every drawn line ends early at the last word that fits — a narrow column needs more lines than the estimate, and the row cut off the tail of the text.

Fix

wrapped_line_count in crates/engine/src/cmd/mod.rs: a greedy word-wrap simulation over the same approx_text_width character estimates — words that don't fit move to the next line whole, a word wider than the column fills the current line then breaks mid-word across lines (what egui does), and inter-word spaces are counted. Multi-line (Alt+Enter) text runs the simulation per line, as before.

Tests

crates/engine/tests/wrap_row_height.rs:

  • wrapped_row_fits_word_wrapped_lines — six-char words in a 10-char column: word wrap needs 4 lines, the old estimate said 3. Fails on main.
  • issue_repro_nasa_sentence — the issue's exact NASA sentence in a 12-char column. Fails on main.

Full gridcraft-engine suite green, clippy 0 warnings, fmt clean.

Co-Authored-By: Claude noreply@anthropic.com

Summary by CodeRabbit

  • Bug Fixes

    • Improved automatic row sizing for wrapped text.
    • Long words now wrap across multiple lines when they exceed the column width.
    • Rows better accommodate word-wrapped content, preventing text from being cut off.
  • Tests

    • Added coverage for long-word wrapping and multi-line row height calculations.

Closes storytold#1969

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0701ce30-fb8a-456b-a035-b1f3107237b7
📥 Commits

Reviewing files that changed from the base of the PR and between 23829d8 and 24ee1e4.

📒 Files selected for processing: 2
  • crates/engine/src/cmd/mod.rs
  • crates/engine/tests/wrap_row_height.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Wrapped row sizing now counts lines using word boundaries and splits words that exceed the column width. Regression tests cover row growth for wrapped text and a NASA sentence in a 12-character column.

Changes: Wrapped row sizing

Layer / File(s) Summary
Word-aware line counting and row-height tests
crates/engine/src/cmd/mod.rs, crates/engine/tests/wrap_row_height.rs
wrapped_line_count counts lines at word boundaries and splits words wider than the column. auto_row_height uses this count for wrapped text. Regression tests cover wrapped-row growth and the NASA sentence case.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: echelon

Merge Risk: ⚪ Minimal · up to 24ee1

Wrapped cells should size more accurately, with regression tests added. No merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: automatic row height now accounts for word wrapping.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@aiongg
aiongg merged commit 2fbb45e into storytold:main Oct 22, 2026
1 check passed
jcagudelo12 added a commit to jcagudelo12/gridcraft that referenced this pull request Nov 2, 2026
…#1969)

The row height of a wrapped cell counts its word-wrapped lines (storytold#2049) with word widths the
front end measures in the font the grid draws with (Session::text_width, the measurer AutoFit
Column Width already uses), at the width the grid wraps at: 2.5 px padding a side, the indent
and a filter button. egui measures at the screen's scale, so the line breaks match the grid's
on scaled displays too. Without a front end (CLI, MCP) word widths stay estimated.

The line count follows egui's wrapping: a word stays on a line only if the space after it fits
too, a line may end after a dash (UAX storytold#14), and a word wider than the column breaks between
characters rather than by its width over the column's.

Session::refit_wrapped_rows refits the rows of wrapped text once a new font set is active
(startup, workbook fonts bound). Rows only grow, custom heights are kept, and it is not an
edit. Undo and redo restore the heights they saved, with no refit.
jcagudelo12 added a commit to jcagudelo12/gridcraft that referenced this pull request Nov 2, 2026
…#1969)

The row height of a wrapped cell counts its word-wrapped lines (storytold#2049) with word widths the
front end measures in the font the grid draws with (Session::text_width, the measurer AutoFit
Column Width already uses), at the width the grid wraps at: 2.5 px padding a side, the indent
and a filter button. Without a front end (CLI, MCP) word widths stay estimated.

The line count follows egui's line breaking (its default SimpleLineBreaker), so the row has
one line per line the grid draws:
- A line may end after a space, a hyphen or other ASCII punctuation, not after an en or em
  dash. A line that runs over ends at its last break of the lowest of those kinds.
- egui checks each character: one that runs over ends the line there when it has no break, so
  a word wider than the column breaks between characters, and that character stays on the
  next line. A line may run half a point past the width (round_output_to_gui).
- egui starts each character on a whole physical pixel, rounded down. The front end gives the
  screen's scale (Session::text_pixels_per_point), so the count matches the grid at 1.5 or 1.6
  px/pt too.

Session::refit_wrapped_rows refits the rows of wrapped text once a new font set is active
(startup, workbook fonts bound). Rows only grow, custom heights are kept, and it is not an
edit. Undo and redo restore the heights they saved, with no refit.
jcagudelo12 added a commit to jcagudelo12/gridcraft that referenced this pull request Nov 18, 2026
…#1969)

The row height of a wrapped cell counts its word-wrapped lines (storytold#2049) with word widths the
front end measures in the font the grid draws with (Session::text_width, the measurer AutoFit
Column Width already uses), at the width the grid wraps at: 2.5 px padding a side, the indent
and a filter button. Without a front end (CLI, MCP) word widths stay estimated.

The line count follows egui's line breaking (its default SimpleLineBreaker), so the row has
one line per line the grid draws:
- A line may end after a space, a hyphen or other ASCII punctuation, not after an en or em
  dash. A line that runs over ends at its last break of the lowest of those kinds.
- egui checks each character: one that runs over ends the line there when it has no break, so
  a word wider than the column breaks between characters, and that character stays on the
  next line. A line may run half a point past the width (round_output_to_gui).
- egui starts each character on a whole physical pixel, rounded down. The front end gives the
  screen's scale (Session::text_pixels_per_point), so the count matches the grid at 1.5 or 1.6
  px/pt too.

Session::refit_wrapped_rows refits the rows of wrapped text once a new font set is active
(startup, workbook fonts bound). Rows only grow, custom heights are kept, and it is not an
edit. Undo and redo restore the heights they saved, with no refit.
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.

2 participants