Commit 2d9bfb8
TextArea: grow by content reliably while editing (#4854)
A growByContent multi-line TextArea was clipping the previous row while
being edited: text would wrap onto a new visual line but the field would
not grow to follow it until focus moved away.
The during-editing grow gate (#4741) decided whether to revalidate using
estimateLineCount(), a character-column prediction (string length vs
getColumns()). The real renderer wraps using font metrics against
getWidth() - horizontalPadding, so with a proportional font text wraps a
row earlier than the character count predicts. The estimate undercounted,
revalidateLater() did not fire, and the field stayed one row short.
Leaving the field ran a normal layout that used the accurate getLines(),
which is why the size corrected itself.
Fix: drop the wrap prediction entirely. Any growth in text length can push
content onto an extra wrapped row, so textMightGrowByContent() now triggers
on a length increase (or an added hard newline) and lets the layout's
getLines() determine the actual size. revalidateLater() coalesces into a
single layout per paint, so erring toward an extra revalidate is cheap and,
crucially, never under-grows. The gate stays width- and EDT-independent and
does not call getLines() from inside setText(), avoiding any layout
re-entrancy. The bogus estimateLineCount() helper is removed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 210c8c3 commit 2d9bfb8
1 file changed
Lines changed: 12 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
622 | | - | |
623 | | - | |
| 621 | + | |
624 | 622 | | |
625 | 623 | | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
632 | 627 | | |
633 | | - | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
634 | 636 | | |
635 | 637 | | |
636 | 638 | | |
| |||
646 | 648 | | |
647 | 649 | | |
648 | 650 | | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | 651 | | |
668 | 652 | | |
669 | 653 | | |
| |||
0 commit comments