Repository navigation
fix(ai-chat-turbo-engine): keep the Yuanbao composer native and the preview scrollable - #277
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
元宝(yuanbao.tencent.com)上的四处问题:
<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 等)粘贴行为不变(有测试固化)。insertText兜底。测试
pnpm check全绿:typecheck + 945 vitest + build。pre不进折叠集合,去掉防护会失败)。待真实站点确认
jsdom 无法复现真实 Quill 的按键行为,合并前请在元宝页面确认: