Skip to content

fix: make Shift+Arrow step 10x work for string steps like "1.00" and scientific notation - #763

Open
young-tree wants to merge 1 commit into
react-component:masterfrom
young-tree:fix/761-shift-string-step
Open

young-tree wants to merge 1 commit into
react-component:masterfrom
young-tree:fix/761-shift-string-step

Conversation

@young-tree

@young-tree young-tree commented Nov 17, 2026 •

Copy link
Copy Markdown

Fixes #761

Problem

getDecupleSteps appended a 0 character to the raw step value when it had no decimal point. Two string-step cases silently produced the same value instead of 10 * step:

  • step="1.00": trimNumber("1.00").fullStr === "1" has no point, so the raw string got a char appended -> "1.000" (still 1, formatted with 3 decimals). Shift+Arrow appeared to do nothing.
  • step="1e-7": scientific notation has no point -> "1e-70" (value off by 10^63).

Fix

Normalize the step to a plain decimal string first (1e-7 -> 0.0000001), then do the digit shift, so it always means multiply by 10:

  • "1.00" -> "10"
  • "1e-7" -> "0.000001"
  • number 1 -> "10" (unchanged behavior)

Tests

Two regression tests added in tests/keyboard.test.tsx (string step with trailing zeros / scientific notation). Full suite: 15 suites, 192 tests passed.

Summary by CodeRabbit

  • Bug 修复
    • 改进数字步长的处理方式,支持科学计数法输入,并修正部分字符串步长的计算结果。
  • 测试
    • 补充键盘操作测试,覆盖字符串步长和科学计数法步长场景。

…scientific notation

getDecupleSteps previously appended a '0' character to the raw step value
when it had no decimal point, which is wrong when the trimmed string step
hides its point ("1.00" -> "1.000", value unchanged) or uses scientific
notation ("1e-7" -> "1e-70").

Now the step is normalized to a plain decimal string first, so digit
shifting always means multiply by 10.

Fixes react-component#761
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

@young-tree 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 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

getDecupleSteps 现在会先规范化步长字符串,并将科学计数法转换为普通十进制表示。新增键盘测试,验证 Shift+Arrow 配合 "1.00" 和 "1e-7" 时触发的值。

Changes

Shift 步长处理

Layer / File(s) Summary
规范化十倍步长并验证键盘行为
src/utils/numberUtil.ts, tests/keyboard.test.tsx
getDecupleSteps 规范化输入,并处理科学计数法和整数形式。新增测试验证 Shift+Arrow 配合 "1.00" 和 "1e-7" 时的 onChange 值。

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

Change: Bug fix

Suggested reviewers: denghuacc

Merge Risk: Minimal · up to bc948

Shift+Arrow now steps by ten times the step for string steps such as "1.00" and scientific-notation steps such as "1e-7". No concrete defect was found, so the change looks safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题准确描述了主要变更:修复 Shift+方向键在字符串步长(如 "1.00")和科学计数法步长(如 "1e-7")下按 10 倍步长变化的问题。摘要显示,getDecupleSteps 现在会将步长规范化为普通十进制字符串,并新增了对应的键盘测试。关联的 issue #761 也描述了同一问题。
Linked Issues check Passed [#761] 目标:字符串步长(如 "1.00"、"1e-7"、1e21)在 Shift+方向键时应按 10 * step 变化。

在 head 的 src/utils/numberUtil.ts 中,getDecupleSteps 执行以下逻辑:
1. 先将输入规范化为 stepStr:number 使用 num2str;字符串使用 trimNumber(step).fullStr。
2. 若…
Out of Scope Changes check Passed 变更范围仅包含 src/utils/numberUtil.ts(getDecupleSteps 的规范化与移位逻辑,约 +7/-2)和 tests/keyboard.test.tsx(两个回归测试)。两处改动均直接对应 #761 的修复与验证,没有发现无关变更。未能通过 diff 操作读取基线与头部的文本差异(变更 blob 在本地检出中缺失),因此依据 head 版本文件内容与 PR 摘要进行判…
Full details: Linked Issues check

Explanation

[#761] 目标:字符串步长(如 "1.00"、"1e-7"、1e21)在 Shift+方向键时应按 10 * step 变化。

在 head 的 src/utils/numberUtil.ts 中,getDecupleSteps 执行以下逻辑:

  1. 先将输入规范化为 stepStr:number 使用 num2str;字符串使用 trimNumber(step).fullStr。
  2. 若 stepStr 含 e/E,则使用 num2str(Number(stepStr)) 展开为普通十进制字符串。
  3. 若 stepStr 不含小数点,则返回 trimNumber(${stepStr}0).fullStr;否则执行原有的小数点移位逻辑。

按代码推算的结果:

  • "1.00" → trimNumber 得到 "1" → 追加 0 得到 "10",符合预期 "10"。
  • "1e-7" → 展开为 "0.0000001" → 移位得到 "0.000001",符合预期。
  • "-1.0" → "-1" → "-10",符合预期。
  • 1e21 → num2str 得到 "1" 后接 21 个 0 → 追加 0 得到 "10000000000000000000000",符合预期。
  • 数字 1 → "10",保持原行为。

测试:PR 描述和变更摘要称在 tests/keyboard.test.tsx 新增两个回归测试("1.00" 预期触发值 11;"1e-7" 预期触发值 1.000001)。本次未读取测试文件内容,测试结果未独立验证。

结论:代码推算满足 #761 的全部编码要求。未发现非编码要求。

Full details: Out of Scope Changes check

Explanation

变更范围仅包含 src/utils/numberUtil.ts(getDecupleSteps 的规范化与移位逻辑,约 +7/-2)和 tests/keyboard.test.tsx(两个回归测试)。两处改动均直接对应 #761 的修复与验证,没有发现无关变更。未能通过 diff 操作读取基线与头部的文本差异(变更 blob 在本地检出中缺失),因此依据 head 版本文件内容与 PR 摘要进行判断。该限制不影响结论,因为变更文件范围与 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

我是小兔,蹦来读步长,
"1.00" 向上,十步正好,
"1e-7" 展开,小数排排好,
键盘测试把结果记牢,
耳朵一竖,开心回窝了!

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: 0b72b863-c43f-4333-bb3b-bee23926dacf
Commits

Reviewing files that changed from the base of the PR and between 868bd31 and bc94876.

Files selected for processing: 2

  • src/utils/numberUtil.ts
  • tests/keyboard.test.tsx

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

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.

Shift+Arrow steps by 1 instead of 10*step for string steps like "1.00" ("1e-7" becomes "1e-70")

1 participant