Skip to content

fix(web): place the sent message edit caret at the end - #1340

Merged
iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
hhucz:fix/sent-message-editor-caret-end
Nov 28, 2026
Merged

iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
hhucz:fix/sent-message-editor-caret-end

Conversation

@hhucz

@hhucz hhucz commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

After stopping a Turn, opening the last sent message for editing used to leave the caret at the start. Focus the inline textarea without scrolling the transcript, place the caret at the end, and scroll the textarea so the last line of a long message is visible.

Initialize only on entry into edit mode. Draft text, sending state, and target changes leave the selection alone while the textarea stays mounted. Canceling and reopening initializes a fresh editor.

Related issues

N/A

UI Demo

Windows Chromium, isolated rendering of the real inline editor with sample text:

Before: first line visible After: last line visible
Before: the caret is at the first line After: the textarea is scrolled to the last line

Test plan

  • npx vitest run --config tests/vitest.config.js apps/web-ui/packages/client/ui-chat/test — 39 passed. The new regression reproduced (0, 0) instead of (10, 10) on the baseline. Coverage includes multiline Chinese and emoji, editing without resetting the selection, cancel and reopen, rejection recovery, and changes to the editable target.
  • Prettier check for both changed files and node tools/check-boundaries.mjs — passed.
  • npm run build:web:ui — passed with Node 22.22.0 after building the workspace dependencies.
  • npm run lint — reported 23 errors in unchanged files. No out-of-scope fixes included.
  • Chromium: verified the caret and internal scroll reach the bottom, the outer scroll stays in place, typing appends, and reopening starts at the end again. No deployment or live Harness/Desktop run. Rejection recovery covers the same mounted textarea; a Host history replacement that remounts it does not carry selection across DOM instances.

🤖 Generated with Claude Code

Focus the inline editor without scrolling the transcript and show the end of long drafts on entry. Preserve the selection on updates to the same draft.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 体验优化
    • 编辑已发送消息时,有草稿且文本框可用时会自动聚焦,光标移至文本末尾并滚动至底部。
    • 发送中、发送失败或目标消息更新时,保留草稿的光标选区。
  • 测试
    • 新增覆盖多行 Unicode 草稿、焦点与光标行为,以及发送失败和目标消息更新场景的测试。

SentMessageEditor 使用 ref 和 effect 管理草稿文本框的焦点、光标位置及滚动位置。新增 jsdom 测试,覆盖打开和取消编辑、发送中、发送被拒绝及目标消息更新时的编辑状态。

Changes: 草稿编辑行为

Layer / File(s) Summary
草稿聚焦与选区验证
apps/web-ui/packages/client/ui-chat/src/client/chat/SentMessageEditor.tsx, apps/web-ui/packages/client/ui-chat/test/sent-message-editor.test.ts
草稿存在且文本框已挂载、未禁用时,组件聚焦文本框、将光标移至末尾并滚动到底部。测试覆盖多行 Unicode 草稿的打开和重新打开,以及发送状态、发送拒绝和目标消息更新时的选区与控件状态。

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

Change: Bug fix

Suggested reviewers: bytepioneer-ai

Merge Risk: Minimal · up to 6ca45

This change focuses the sent-message editor without scrolling the transcript, places the caret at the end of the text, and scrolls long messages to their last line. The change is localized to one component and has reported test coverage. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(web): place the sent message edit caret at the end”与变更内容直接相关。摘要显示 SentMessageEditor 通过 effect 在进入编辑时将光标移至文本末尾并滚动到底部,PR 目标也是如此。标题简洁、具体,足以说明主要变更。
Description check Passed 描述说明了问题(停止 Turn 后编辑最后一条已发送消息时光标停在开头)以及修复方式(聚焦文本框、光标移至末尾、滚动到最后一行,且仅在进入编辑模式时初始化)。描述还列出了测试计划,与变更集相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

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

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

Commits

Reviewing files that changed from the base of the PR and between 30df393 and 6ca4562.

Files selected for processing: 2

  • apps/web-ui/packages/client/ui-chat/src/client/chat/SentMessageEditor.tsx
  • apps/web-ui/packages/client/ui-chat/test/sent-message-editor.test.ts

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

Recent review details

Context from checks skipped due to timeout: 8

  • GitHub Check: CodeRabbit
  • GitHub Check: Check macos-26
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Check windows-latest
  • GitHub Check: Static checks
  • GitHub Check: Vitest
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Web Host tests
Additional context used

Code guidelines: 1

docs/product/standalone-web.md — auto-discovered
Path-based instructions: 1

Applicability reference: AGENTS.md: # Repository Guidelines `npm start` / `npm start web` rebuild and relaunch the user's Desktop / Web and may restart the shared Host; `npm stop` stops all local codexhost services across worktrees.

CodeRabbit inference engine (docs/product/standalone-web.md)

Files:

  • apps/web-ui/packages/client/ui-chat/src/client/chat/SentMessageEditor.tsx
  • apps/web-ui/packages/client/ui-chat/test/sent-message-editor.test.ts
Learnings: 1

Learning: 2026-11-27T09:29:53.369Z

Learnt from: CR
Repo: BytePioneer-AI/codex-host PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-11-27T09:29:53.369Z
Learning: Source excerpt:
# Repository Guidelines

## Testing & Completion

- Do not write browser, e2e, or component tests for Web pages (`apps/web-ui`); the user checks page changes directly. Codex Desktop compatibility after an update is checked with `npm run audit:codex-desktop` and `npm run probe:renderer-binding` (`codexhost-update-impact-audit`).

Applied to files:

  • apps/web-ui/packages/client/ui-chat/test/sent-message-editor.test.ts

@iruriQ
iruriQ merged commit 9cc9423 into BytePioneer-AI:main Nov 28, 2026
6 of 8 checks passed
@iruriQ

iruriQ commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

感谢贡献,已合并到 main!

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.

2 participants