Skip to content

fix: account for word-spacing in TextArea autoSize - #210

Open
wozhenbang2004 wants to merge 2 commits into
react-component:masterfrom
wozhenbang2004:fix-textarea-word-spacing
Open

wozhenbang2004 wants to merge 2 commits into
react-component:masterfrom
wozhenbang2004:fix-textarea-word-spacing

Conversation

@wozhenbang2004

@wozhenbang2004 wozhenbang2004 commented Nov 12, 2026 •

Copy link
Copy Markdown

Copy word-spacing to the hidden textarea so autoSize measures the same line wrapping as the visible textarea.

Added regression coverage for positive, negative, and normal word spacing. Tests, lint, type check, compile and build pass.

Fixes #209

Chrome reproduction of the height calculation in isolation, with the same text and styles before and after the fix:

textarea-word-spacing-clean

Summary by CodeRabbit

  • Bug Fixes
    • 修复文本区域尺寸测量时未保留字间距的问题;不同字间距设置现在会应用于测量样式。

@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

@wozhenbang2004 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

自动尺寸测量样式新增 word-spacing。测试更新了 sizingStyle 预期值,并验证隐藏的测量用 textarea 会保留多种 wordSpacing 值。

Changes

TextArea 字间距测量

Layer / File(s) Summary
复制字间距并验证测量样式
src/calculateNodeHeight.tsx, tests/TextArea.test.tsx
SIZING_STYLE 新增 word-spacing。测试更新预期样式,并验证隐藏的测量用 textarea 会保留 8px、16px、-2px 和 normal。

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

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 46a20

Auto-sized text areas will now account for custom word spacing, so wrapping and height should match the visible text area. No merge-blocking risk is apparent.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: account for word-spacing in TextArea autoSize”准确描述了主要变更。变更将 word-spacing 加入 SIZING_STYLE,使自动高度测量用的隐藏 textarea 与可见 textarea 的换行一致。标题指出了 TextArea autoSize 与 word-spacing 这两个关键点,并使用 fix 前缀说明这是缺陷修…
Linked Issues check Passed [#209] 要求:自动高度测量用的隐藏 textarea 必须复制 word-spacing,使换行计算与可见 textarea 一致。已在 reviewed head 的 src/calculateNodeHeight.tsx 中确认:SIZING_STYLE 数组包含 'word-spacing'(位于 'letter-spacing' 之后)。calculateNodeStyling 会把…
Out of Scope Changes check Passed 变更范围仅包含两处:src/calculateNodeHeight.tsx 中 SIZING_STYLE 新增一项 'word-spacing'(+1 行),以及 tests/TextArea.test.tsx 中的预期字符串更新和 word-spacing 回归测试(约 +18/-1 行)。这些变更直接服务于 #209 的目标,未发现无关改动。未能通过 diff 工具读取完整文本差异(chang…
Full details: Title check

Explanation

标题“fix: account for word-spacing in TextArea autoSize”准确描述了主要变更。变更将 word-spacing 加入 SIZING_STYLE,使自动高度测量用的隐藏 textarea 与可见 textarea 的换行一致。标题指出了 TextArea autoSize 与 word-spacing 这两个关键点,并使用 fix 前缀说明这是缺陷修复。

Full details: Linked Issues check

Explanation

[#209] 要求:自动高度测量用的隐藏 textarea 必须复制 word-spacing,使换行计算与可见 textarea 一致。已在 reviewed head 的 src/calculateNodeHeight.tsx 中确认:SIZING_STYLE 数组包含 'word-spacing'(位于 'letter-spacing' 之后)。calculateNodeStyling 会把该数组的每一项转为 name:value 并写入隐藏 textarea 的 style 属性,因此 word-spacing 会被复制。PR 摘要说明测试文件新增参数化测试,验证 wordSpacing 为 8px、16px、-2px 和 normal 时隐藏 textarea 保留对应样式,并更新了预期 sizingStyle 字符串。未直接读取测试文件内容,该结论基于 PR 摘要。无需非编码任务。

Full details: Out of Scope Changes check

Explanation

变更范围仅包含两处:src/calculateNodeHeight.tsx 中 SIZING_STYLE 新增一项 'word-spacing'(+1 行),以及 tests/TextArea.test.tsx 中的预期字符串更新和 word-spacing 回归测试(约 +18/-1 行)。这些变更直接服务于 #209 的目标,未发现无关改动。未能通过 diff 工具读取完整文本差异(changed blobs 在当前检出中缺失),因此结论依据 head 文件内容与 PR 摘要。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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

我是小兔,轻轻跳,
字间距也量得到。
隐藏文本框照着抄,
四种间距都记牢。
自动尺寸更合拍,
我抱胡萝卜蹦蹦跑。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 11519396-d09c-4194-8fcc-de60bff7cc1b
Commits

Reviewing files that changed from the base of the PR and between 39f4ae6 and 46a201b.

Files selected for processing: 2

  • src/calculateNodeHeight.tsx
  • tests/TextArea.test.tsx

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

@wozhenbang2004
wozhenbang2004 marked this pull request as ready for review November 12, 2026 09:34

This branch has not been deployed

No deployments
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.

TextArea autoSize does not account for word-spacing

1 participant