Skip to content

fix(ai-chat-turbo-engine): keep the Yuanbao composer native and the preview scrollable - #277

Merged
CYoJkoY merged 1 commit into
mainfrom
ai-chat-turbo-yuanbao-composer-paste-preview
Dec 1, 2026
Merged

CYoJkoY merged 1 commit into
mainfrom
ai-chat-turbo-yuanbao-composer-paste-preview

Conversation

@CYoJkoY

@CYoJkoY CYoJkoY commented Dec 1, 2026

Copy link
Copy Markdown
Owner

问题

元宝(yuanbao.tencent.com)上的四处问题:

  1. Backspace 多删空行 — 引擎写入后 DOM 与 Quill blot 模型不一致。
  2. Shift+Enter 在光标上方换行 — 同一根因,caret 落位错误。
  3. 粘贴变引用块/富文本 — Quill 读取剪贴板 HTML flavour。
  4. 伪文件「查看」预览无法滚动 — 预览弹窗的 <pre> 被引擎自己的代码折叠扫描识别并折叠。

修复(均在引擎自有逻辑内,无站点 DOM hack)

  • composer.ts:清空改走 delete 命令;insertHTML 兜底对段落编辑器(.ql-editor/rich-textarea)提供逐行 <p> 标记(空行 <p><br></p>);写入后把光标折叠到最后一个块内。根因已写入注释。
  • config.ts + virtual-files.ts:新增 pastePlainText 平台开关(仅元宝启用),paste/beforeinput 拦截后只取 text/plain 插入;超过伪文件阈值的长文本仍走伪文件流程;插入前先读光标再 focus,光标不在编辑器内时回落到编辑器末尾,不丢文本。
  • code-blocks.ts + config.ts:ENGINE_UI_SELECTOR(含 #ai-turbo-vf-preview-modal、.ai-turbo-modal-backdrop)从代码折叠扫描中排除。

兼容性

  • pastePlainText 为可选平台字段,其它平台(ChatGPT/Gemini 等)粘贴行为不变(有测试固化)。
  • 代码折叠仅在非引擎 UI 上生效;dehydrated 等既有排除不变。
  • 清空路径对 textarea/其它编辑器保留原 insertText 兜底。

测试

  • pnpm check 全绿:typecheck + 945 vitest + build。
  • 新增:composer 段落标记/清空/光标折叠/insertHTML 标记 5 项;纯文本粘贴 5 项(含 HTML flavour 丢弃、quotation beforeinput、其它平台不拦截、长文本仍转伪文件、光标在兄弟块);代码折叠 2 项(预览 pre 不进折叠集合,去掉防护会失败)。

待真实站点确认

jsdom 无法复现真实 Quill 的按键行为,合并前请在元宝页面确认:

  • Backspace 一次只删一个字符/换行,不连带空行
  • Shift+Enter 在当前光标处向下换行
  • 复制页面文本粘贴进输入框是纯文本(无引用块/加粗)
  • 粘贴超长文本仍出现伪文件托盘,「查看」弹窗可完整滚动、无折叠条
  • 抽查 ChatGPT/Gemini:输入、Enter 发送、代码折叠正常

…review scrollable

The Yuanbao composer is a Quill `ql-editor`, and the engine's writes left it
in a state where Backspace and Shift+Enter acted on the wrong block. A clear or
a fallback write went through `insertHTML` with one `white-space: pre-wrap`
div, but Quill keeps one block per line: the DOM and its blot index no longer
matched, so the next Backspace swallowed a whole blank line and Shift+Enter
broke above the line the caret was on. The write also left the select-all range
in place for a host that ignored the commands, which put the same two keys at
the top of the document.

The write path now clears through `delete`, hands a paragraph editor `<p>`
markup, and collapses the caret into the last block. Paste in the Yuanbao
composer is reduced to the `text/plain` flavour, because a page copy arrives as
`insertFromPasteAsQuotation` and Quill renders it as a 引用 block; a paste
above the virtual-file threshold still becomes a file. The text preview's `pre`
is excluded from the code-fold scan, so a long file scrolls inside the dialog
instead of being clamped to the preview height.
@CYoJkoY
CYoJkoY merged commit f86a16e into main Dec 1, 2026
1 check passed
@CYoJkoY
CYoJkoY deleted the ai-chat-turbo-yuanbao-composer-paste-preview branch December 1, 2026 12:54
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.

1 participant