Skip to content

feat(web): 用户消息原位编辑,保存与重试平滑定位 - #1665

Merged
qqqqqf-q merged 13 commits into
felinics:mainfrom
qqqqqf-q:feat/memoh-214-in-place-user-edit
Nov 3, 2026
Merged

qqqqqf-q merged 13 commits into
felinics:mainfrom
qqqqqf-q:feat/memoh-214-in-place-user-edit

Conversation

@qqqqqf-q

@qqqqqf-q qqqqqf-q commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

问题

  • 编辑已发送的提问时,编辑态换成一个固定宽度(最多 42rem)的灰底容器和 14px 输入框,和 16px 的气泡差别很大;单行消息点编辑后宽度、高度、字号全变。「取消」「发送」被压成文字大小,放在输入框内部。
  • 在页面底部保存编辑或点重试时,本轮的旧回复被清掉,页面变矮,视图在一帧内硬跳(修复前在旧基线上测得:这一轮从 698px 一帧缩到 179px,提问跳了 55px)。

改动后

  • 原位编辑:气泡原地变成输入框,位置、盒子、字形和底色都与气泡一致,未聚焦时没有边框,看起来就是原来的气泡;聚焦时才出现输入框边框(浅色近黑,深色品牌色)。气泡下方的复制/编辑行原地换成「取消」(ghost)和「保存」(primary),旁边的 ⓘ 说明「保存后会替换这条消息和它之后的回复」。快捷键不变(⌘/Ctrl+Enter 保存,Esc 取消);输入法正在组字时按这些键不会提交或取消。
  • 触屏长按菜单:触屏没有悬停,气泡下方的复制/编辑行在手机上一直看不到,编辑没有入口。现在在触屏上长按气泡(500ms,手指移动超过 10px 视为滚动取消),在气泡下方弹出「复制」「编辑」菜单,位置贴着气泡而不是手指,避免挡住提问。鼠标设备不受影响。保存后菜单不会再弹出。
  • 保存后直接折回气泡:编辑后的提问在 store 里是一条新消息,这里让它借用原消息的渲染 key,组件不重新挂载,输入框原地变回气泡。借用只影响 Vue key,不改 store 里的 id;被借的 key 再出现时自动让开,不会产生重复 key。发送没能开始时恢复原提问,输入框带着草稿重新打开。编辑框是否打开和草稿内容由聊天面板按 turn id 保存(useUserEditDraft),不只存在消息组件里:聊天记录刷新会给消息换 id 并重建组件,之前保存失败后的那次刷新会把重新打开的编辑框和草稿一起丢掉。
  • 保存/重试平滑定位:和发送一样把提问平滑滚到固定位置。滚动期间这一轮先保持原高度,落定后再收回到回复所需的预留高度;只有要收回的部分完全在视口下方时才收回,所以页面不会跳。
  • 提问字形统一:气泡与编辑框共用一条 .chat-user-text 规则(<textarea> 不能按文字类型分段设字重,改由字体本身承担拉丁字母的补偿),进入编辑不改变任何字形;用户自定义 UI 字体时跟随自定义字体。
  • 组件库:边框选项和 ⓘ 都来自 @felinic/ui(Textarea rest="bare" / surface="brand-tint",新组件 InfoHint,触屏轻点可打开),Memoh 侧不再有自定义颜色或手写 Tooltip。packages/ui 指向 feat(ui): Textarea 增加原位编辑与品牌色底选项,新增 InfoHint ui#38 合并后的 main 提交 598f229。

Related Issues

Validation

自动检查(agent 本地执行)

  • pnpm --filter @memohai/web typecheck 通过;packages/ui 的 vue-tsc --build 通过
  • 改动文件 eslint 0 error;node scripts/check-ui-contract.mjs 通过
  • vitest:useChatScroll、message-item、chat-pane-send、typography 四个测试文件 61 例全部通过。message-item.test.ts 的 @felinic/ui 替身补了 InfoHint(新组件,原替身里没有)
  • web 全量 vitest:2346 例通过;5 例失败(ui-icon-contract ×2、model-setting ×2、chat-user-input-form ×1)另有 2 个文件加载失败,在干净的 origin/main 上同样失败,与本 PR 无关。本机 Node 25 需加 NODE_OPTIONS=--no-experimental-webstorage,否则 Node 自带的 localStorage 会遮住 jsdom 的实现

浏览器实测(agent 用浏览器操作,不是 Human QA)

  • 环境:本 PR 分支的 web(vite,http://127.0.0.1:8083)连本地 OSS 开发后端;后端跑的是较旧的提交,本 PR 不改后端
  • 新建一个两轮、每轮约 400 字回复的会话:
    • 进入编辑:输入框与气泡同位置、同字形;聚焦时浅色为 oklch(0 0 0 / 0.78)、深色为 oklch(0.72 0.16 290);ⓘ 悬停向上弹出说明
    • 在离底部 171px 处保存编辑,逐帧记录提问位置:约 300ms 平滑滑到固定位置,单帧最大位移 18px;滑动期间这一轮保持 711px,之后收回到 407px,滚动位置不变
    • 在页面最底部点重试:约 370ms 平滑滑到位,单帧最大位移 24px;636px 保持后收回到 407px,滚动位置不变
    • 用真实鼠标悬停提问后点「编辑」,正常进入编辑
  • 触屏模拟(浏览器触屏仿真,非真机):长按气泡在气泡下方弹出复制/编辑菜单;点编辑进入编辑,保存后菜单不再弹出
  • 未在浏览器里验证的最新改动:未聚焦无边框(rest="bare")、ⓘ 14px 与触屏轻点打开,只跑了 typecheck 和 eslint
  • 未覆盖:真机、Desktop 客户端、发送失败后带草稿重新打开(没有在浏览器里制造失败)

本轮修复与复测(agent 用浏览器操作,不是 Human QA;环境:本 PR 分支 web http://localhost:8214 连本地 OSS 开发后端)

  • 保存失败丢草稿(见下方 Agent QA 记录):已修复。复现方式同记录:先在会话里选好测试模型,再临时停用该模型后保存编辑,后端在开始前拒绝。修复前:约 0.2 秒时编辑框带草稿重开,约 1 秒后聊天记录刷新、消息换 id,编辑框和草稿消失。修复后:经过两次刷新换 id,编辑框最终仍带着新草稿打开,焦点在输入框内(截图见下)。测试后模型已恢复启用
  • 取消编辑:编辑框关闭,草稿不残留
  • 编辑后由后端接受、回复阶段报错(测试模型返回 400):编辑生效,显示错误回复,编辑框不重新打开(符合预期:这一轮已经替换)
  • 另修两处滚动状态问题:编辑换 id 后从滚动锚点里删掉旧 id;切换会话时作废上一个会话尚未执行的置顶回滚,避免晚到的失败把旧会话的滚动状态套到新会话(普通发送也受益)。这两处只做了代码和测试层面的确认,没有在浏览器里构造对应时序
  • 已合入最新 main;pnpm --filter @memohai/web typecheck、改动文件 eslint、useChatScroll / message-item / chat-pane 相关测试(47 例)通过。合并提交因 pre-commit 的 Go lint 对 main 带入的全部 Go 包超时(180s)而用 --no-verify 提交,Go 改动均来自 main

保存失败后编辑框带着草稿重新打开

Screenshots / Recordings

以下截图来自较早的版本(ⓘ 为 12px,尚无长按菜单)。

浅色:编辑框聚焦(与气泡同位置、同字形)

浅色编辑框聚焦

ⓘ 向上弹出说明

InfoHint 说明

保存编辑后:提问平滑停在固定位置,新回复从下方开始

保存编辑后

页面底部点重试后:提问平滑停在同一位置

重试后

Human QA

  • Human QA passed

Agent QA follow-up — 2026-10-30

以下是针对旧 head 41f58f2 的记录;其中的丢草稿问题已在 1d7c14565 修复,见上方「本轮修复与复测」。

本地真实浏览器验收结论:未通过完整验收,存在失败保存后丢草稿的问题。这是 Agent QA,不是 Human QA。

  • 环境:独立 worktree / Docker Compose 栈 memoh-pr1665-qa,Web http://localhost:18082,Server 18080,Channel 18081。Server/Web 均运行本 PR head 41f58f2;UI 子模块 637a311,独立数据库。
  • 真实模型:MiMo V2.6 Pro(mimo-v2.6-pro),真实服务生成,正常流程未使用 mock 回复。
  • 通过:中英文单行气泡进入编辑后位置/尺寸/字形/底色一致(440.84 × 47.68px);浅色与深色聚焦边框、失焦无边框、说明提示、Esc 取消;编辑保存后立即恢复气泡并生成新回复;底部重试;Chrome 400px 触屏仿真的长按菜单、菜单进入编辑、轻点 InfoHint、保存后菜单不重新打开;Command+Enter 保存;刷新后保留新提问及新回复。
  • 重试连续 DOM 采样:轮次从约 698px 保持到滚动完成,再降到 446px,提问最终稳定在 y≈180px。保存采样亦观察到旧高度保持后收回,但未捕获完整起始动画;这些是浏览器采样,不是逐视频帧性能保证。
  • 失败(三次复现,包含刷新后重试): 编辑已有提问,输入新草稿,在隔离 QA 后端临时禁用该模型再点保存,后端在输出前报 chat model mimo-v2.6-pro is disabled。旧提问与旧回复恢复,但编辑框未重新打开;再次点击编辑只出现原提问,新草稿已丢失。测试后模型已重新启用。预期应恢复带草稿的编辑框。相关路径:message-item.vue 的 submitEdit / 回调与 chat-pane.vue 的 handleEditMessage / 渲染 key 复用。
  • 自动检查:本次重跑 useChatScroll、message-item、chat-pane-send、typography 四个测试文件,共 61 例通过。
  • 未覆盖:移动真机、Electron Desktop、真实中文输入法候选态、Ctrl+Enter、自定义字体、精确的 10px 长按移动取消边界。浏览器仿真不等同于真机验收。
  • 环境观察:MiMo 健康探测返回 400,但真实聊天生成成功;浏览器控制台另有 Cannot read properties of undefined (reading 'global') 初始化错误,本次未归因于该 PR。

以下附件均为本次当前 head 的新截图;失败截图展示旧消息已恢复、错误提示出现而编辑框缺失,随后重开编辑只有旧文本。

Current-head QA: light editor preserves the user bubble layout

Current-head QA failure reproduction: new draft before saving

Current-head QA failure: old turn restored but editor and new draft are lost

Current-head QA: touch-emulated long press menu

Current-head QA: touch tap opens the edit explanation

Current-head QA: real MiMo reply after touch save, menu remains closed

- 编辑已发送的提问时,气泡原地变成输入框:盒子、字形、底色与气泡一致,
  只多出输入框边框(Textarea engage="hover" + surface="brand-tint");
  下方操作行原地换成「取消」「保存」,旁边用 InfoHint 说明保存会重跑本轮
- 保存后编辑后的提问沿用原组件(渲染 key 借用),输入框直接折回气泡
- 保存与重试时本轮先保持原高度、平滑滚到固定位置,落定后再收回预留高度,
  修复在页面底部保存/重试时页面一帧硬跳
- 提问正文统一走 .chat-user-text,气泡与编辑框字形一致
- packages/ui 指向 felinics/ui 的 Textarea / InfoHint 改动

Refs: MEMOH-214, MEMOH-222
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T15:00:36.192149Z a3bc2cc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:S PR size uses the larger of added or deleted lines, excluding generated files labels Oct 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a3bc2ccb61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

throw error
})
// A failed start restores the old reply; put the view back with it.
if (!(result.ok || result.stage === 'stream')) rollbackPin?.()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Invalidate restart rollbacks after switching sessions

When a reusable preview tab is repointed to session B while session A's retry/edit is still awaiting output, a no-output failure reaches this rollback after the switch. The sessionId watcher in useChatScroll.ts:673-689 clears the pin but does not advance pinAttemptId, so armPin accepts the stale closure and restores A's saved follow mode, reserves, and scrollTop into B; the store already exercises these late-failure flows in chat-list.test.ts:2896-2916 and 3083-3109. Capture/compare the session ID or invalidate the attempt when the pane changes sessions.

AGENTS.md reference: apps/web/AGENTS.md:L330-L332

Useful? React with 👍 / 👎.

Comment on lines 531 to 532
watch([isVisible, toRef(props, 'isScrolling'), () => props.message.id], () => {
emit('active', isVisible.value, { id: props.message.id, top: ((messageEl.value?.getBoundingClientRect().top ?? 0) - 48) })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove the prior ID from the active-anchor map

When an edit reuses this MessageItem under a replacement ID, the watcher emits an active event only for the new ID, leaving the old ID in useChatScroll's elId map. After the new row later becomes inactive, the stale old entry can remain the closest anchor; on KeepAlive activation onActivatedRestoreScroll selects it, fails to find its removed DOM node, and skips restoring a valid live anchor, so returning to the chat can lose the reading position. Emit an inactive event for the previous ID (or delete it explicitly) when the ID changes.

AGENTS.md reference: apps/web/AGENTS.md:L330-L332

Useful? React with 👍 / 👎.

- 触屏设备长按用户消息弹出复制/编辑菜单,悬停才出现的操作行在触屏上无法使用
- 保存旁直接显示"保存后会替换之后的回复",不再藏在触屏打不开的悬停提示里
- 输入法选词时 Enter/Esc 交给输入法,不再提交或取消编辑
- 更正两处已过时的注释
- 长按改用下拉菜单,贴着气泡下沿、按气泡一侧对齐弹出,不再从手指位置弹出挡住消息
- 新增 useLongPress:按住约半秒触发,移动超过 10px(开始滚动)即取消
- 保存旁恢复提示图标,去掉单独的提示小字
@github-actions github-actions Bot added size:M PR size uses the larger of added or deleted lines, excluding generated files and removed size:S PR size uses the larger of added or deleted lines, excluding generated files labels Oct 28, 2026
@chen-ran

Copy link
Copy Markdown
Member

在当前 head 的本地开发环境验证时,复现了保存失败后丢失草稿的问题:

  1. 编辑最后一条用户消息,输入与原消息不同的新文本。
  2. 在后端临时禁用当前模型,然后点击保存,使请求在输出前失败。
  3. 页面恢复了原提问和原回复,并显示错误提示,但编辑框没有重新打开。
  4. 再次点击“编辑”时只显示原提问,刚才输入的新草稿已丢失。
    该问题已复现 3 次,包括刷新页面后的复测。submitEdit() 在发送前调用 cancelEdit() 清空草稿,后续依靠 done(false) 回调中的 openEditor(draft) 恢复;但这条恢复路径在实际失败回滚后没有生效。建议检查消息替换、回滚期间的组件实例与渲染 key 是否保持一致,确保恢复操作作用于当前显示的消息组件。

预期行为是:请求未能开始输出时,恢复旧轮次,并重新打开带有本次草稿的编辑框,让用户可以直接重试。建议补一个覆盖“编辑 → 保存失败 → 旧轮次恢复 → 草稿仍在编辑框中”的回归测试,并用真实 UI 复验。

@qqqqqf-q
qqqqqf-q merged commit 8a9353f into felinics:main Nov 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:M PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants