Skip to content

fix(sender): delete newlines before slots - #2034

Open
advance-hub wants to merge 1 commit into
ant-design:mainfrom
advance-hub:codex/fix-slot-newline-backspace
Open

fix(sender): delete newlines before slots#2034
advance-hub wants to merge 1 commit into
ant-design:mainfrom
advance-hub:codex/fix-slot-newline-backspace

Conversation

@advance-hub

@advance-hub advance-hub commented Aug 25, 2026

Copy link
Copy Markdown

Why

In Chromium, pressing Enter immediately before a non-editable Sender slot creates a new block that starts with <br>. Backspace removes the break node but leaves the block wrapper, so the visual newline cannot be deleted.

Fixes #1889.

What changed

  • Detect a collapsed caret at the start of a slot-led block.
  • Remove the leading break and unwrap the block into the editor.
  • Preserve the slot DOM and restore the caret immediately before it.
  • Add a regression test for Enter then Backspace before a slot.

Verification

  • Sender slot Jest suite: 23 passed.
  • TypeScript --noEmit check passed.
  • Biome and git diff --check passed.
  • Real Chromium before/after reproduction passed.

Before / After

Before: Backspace removes <br>, but the block wrapper keeps the newline.

before.mp4

After: Backspace merges the line while preserving the slot and caret position.

after.mp4

Changelog: Fix Sender slot mode being unable to delete a newline immediately before a slot.

Summary by CodeRabbit

  • Bug 修复
    • 修复编辑器中退格删除操作的问题:光标位于不可编辑插槽前的换行处时,可正确移除换行并合并内容。
    • 优化插槽内容删除后的光标位置与内容变更处理。

Why:
- Chromium leaves a block wrapper when Backspace removes the leading break from a line that starts with a non-editable slot.
- The remaining wrapper keeps the visual newline even though the break node is gone.

What:
- Detect the collapsed caret at the affected slot line boundary.
- Unwrap the line, preserve the slot nodes, and restore the caret before the slot.
- Add a regression test for Enter then Backspace before a slot.

Testing:
- Sender slot Jest suite (23 tests)
- TypeScript noEmit check
- Biome check and git diff --check
- Real Chromium before/after interaction
@dosubot dosubot Bot added the bug Something isn't working label Aug 25, 2026
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 271ea24c-ad8c-46a1-8222-a2e8c2d0d31a

📥 Commits

Reviewing files that changed from the base of the PR and between 25aad7b and 8d052ad.

📒 Files selected for processing (2)
  • packages/x/components/sender/__tests__/slot.test.tsx
  • packages/x/components/sender/components/SlotTextArea.tsx

Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

Sender 新增 Chromium 下的退格处理:删除 slot 前的换行块,提升 slot 节点,恢复光标并触发一次 onChange。测试覆盖该行为。

Changes

Sender slot 换行删除

Layer / File(s) Summary
退格删除换行与测试
packages/x/components/sender/components/SlotTextArea.tsx, packages/x/components/sender/__tests__/slot.test.tsx
当光标位于 slot 前的换行块起始位置时,代码移除 <br>,提升行内节点,恢复光标并阻止默认退格行为。测试验证事件返回 false、换行块被移除、slot 成为根节点直接子节点,并且 onChange 只调用一次。

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

Merge Risk: ⚪ Minimal · up to 8d052

This localized Sender fix removes the unwanted newline before a slot while preserving the slot and caret; no actionable merge-blocking risk remains after normal checks and review.

Poem

小兔按下 Backspace,
换行轻轻跳出框。
slot 越过旧行到根节点,
光标回到清晰位置,
onChange 唤醒一次,
Chromium 也不再迷路。

🚥 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 标题准确概括了 Sender slot 前删除换行的主要修复内容,简洁且明确。
Linked Issues check ✅ Passed 代码修复了 Issue #1889 描述的问题:在 slot 前按 Enter 后,Chromium 中按 Backspace 可以删除换行,同时保留 slot 和光标位置。新增回归测试覆盖该场景。
Out of Scope Changes check ✅ Passed 变更仅涉及 Sender 的换行删除逻辑和对应回归测试,均与 Issue #1889 直接相关。未发现无关或超出范围的代码变更。
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…
Full details: Docstring Coverage

Explanation

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 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@nrps9909 nrps9909 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 8d052ad against base 25aad7b.

The Chromium newline repair is narrowly gated to a collapsed Backspace selection at offset 0 in a direct child block whose leading nodes are BR plus a registered slot. It removes only that BR and wrapper, preserves the remaining nodes in order, restores the caret immediately before the first slot, and emits one value change.

Validation performed:

  • Reverted the new repair branch locally: the submitted regression test failed at the expected event/default-prevention assertion.
  • Exact head Sender slot suite: 23/23 passed.
  • Temporary complementary probes passed for multiple slots with intervening/trailing text, exact DOM order preservation, caret range at the original line index, one onChange, and non-collapsed selection remaining untouched.
  • packages/x TypeScript noEmit passed.
  • Biome passed on both changed files.
  • git diff --check passed.
  • Live PR head rechecked before review and still matches the tested SHA; current remote checks are green.

AI assistance disclosure: Codex was used to inspect the exact diff, run the red/green validation and complementary boundary probes, and draft this review. I verified the reported commands and outcomes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

antdx sender slot 在一个slot前面回车之后, 那个回车删不了了

2 participants