Skip to content

fix: stop measure when the anchored prefix is removed - #339

Open
dogledogle wants to merge 1 commit into
react-component:masterfrom
dogledogle:fix/stop-measure-when-prefix-removed
Open

fix: stop measure when the anchored prefix is removed#339
dogledogle wants to merge 1 commit into
react-component:masterfrom
dogledogle:fix/stop-measure-when-prefix-removed

Conversation

@dogledogle

@dogledogle dogledogle commented Sep 8, 2026

Copy link
Copy Markdown

fix ant-design/ant-design#27426

问题

文本中已有一个 @ 时,再输入一个 @ 打开候选框,随后按 Backspace 删除它,候选框会关闭后立刻重新出现在前一个 @ 的位置,并显示 Not Found。

原因

删除前缀符只更新了文本,测量状态未终止。随后的 keyup 会查找光标前最后一个 @(即文本中更早的旧 @),而原有逻辑只要测量中就无条件重新测量,于是错误地锚到了旧 @ 上。

修复

测量进行中时校验原测量位置的前缀符是否还存在:

  • 已被删除则直接停止测量,不再跳转到更早的前缀,同时不再用无效文本触发 onSearch
  • 其余行为(输入/删除搜索字符、ESC/Enter/方向键、AZERTY 键盘、多前缀配置等)保持不变。

测试

  • 新增回归测试 stop measure if remove prefix and previous prefix exists(未修复时失败,修复后通过);
  • 全量测试 55/55 通过,快照无变化;tsc、eslint 通过。

Summary by CodeRabbit

  • Bug Fixes

    • 修复删除刚输入的 @ 前缀后,提及测量状态未正确停止的问题。
    • 避免系统错误地重新定位到文本中更早存在的 @ 前缀。
  • Tests

    • 新增测试,验证删除当前测量前缀后提及测量会停止。

Removing the prefix char (e.g. the `@` just typed) used to re-anchor
the measure to an earlier prefix in the text, keeping the dropdown
open with wrong search text. Stop measuring instead, and skip the
stale onSearch fire.

Note: when text before the prefix shifts while measuring, the measure
also stops now instead of re-anchoring to the shifted prefix.
@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

@dogledogle 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 Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 689944fc-33e9-4dfb-8ba8-cee8314a26d3

📥 Commits

Reviewing files that changed from the base of the PR and between 7b50687 and fb8fe6f.

📒 Files selected for processing (2)
  • src/Mentions.tsx
  • tests/FullProcess.spec.tsx

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

本次变更更新 onInternalKeyUp 的测量前缀判断。当用户删除当前测量前缀时,组件停止测量,不再重新定位到文本中更早的前缀。新增测试覆盖该场景。

Changes

测量前缀处理

Layer / File(s) Summary
前缀删除处理与测试
src/Mentions.tsx, tests/FullProcess.spec.tsx
onInternalKeyUp 检查当前选择位置是否仍包含测量前缀。前缀被删除时调用 stopMeasure()。新增测试验证存在更早 @ 时不会重新锚定。

Priority: ⬇️ Low — Defer this mentions-input fix because it narrowly prevents a stale empty-results dropdown after deleting an @ prefix.

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

Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to fb8fe

The change stops mention measurement when its active prefix is deleted, preventing a stale empty-results dropdown from reopening. No merge-blocking risk remains.

Suggested reviewers: qdyanbing, afc163, emilyyyliu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题“fix: stop measure when the anchored prefix is removed”准确概括了主要修复内容:删除锚定前缀时停止测量。标题简洁且与变更直接相关。
Linked Issues check ✅ Passed 变更满足问题 #27426 的要求。代码检查锚定的测量前缀是否仍存在;当前缀被删除时调用 stopMeasure(),因此不会重新显示“Not Found”下拉框。新增回归测试验证了该行为。
Out of Scope Changes check ✅ Passed 变更仅涉及 Mentions 测量逻辑和对应的回归测试。所有变更都服务于问题 #27426,未发现无关或超出范围的代码变更。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

小兔挥爪改测量,
删除前缀即停航。
旧的符号不再追,
测试守住新方向。
胡萝卜旁庆功忙。

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

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.

mentions 使用onchange的情况下输入 @ 符号在删除之前的@符号会弹出无数据

1 participant