Files
Mdeical_Sur_Report/工程分析/20260419_2030/需求分析.md
admin 7275906f3c fix(editor): AI注入后Ctrl+Z失效 + 字体格式统一
- confirmAiInjection改用Range.selectNodeContents + execCommand('insertHTML')保留浏览器撤销栈
- handleAIGenerate中对cleanHtml增加<p>标签内联样式注入:padding 0px、font-family SimSun、font-size 12pt、line-height 1.5
- 确保AI替换后的文字字体与原有文字完全一致
2026-04-19 20:33:43 +08:00

30 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 需求分析
## 时间戳
2026-04-19 20:30
## 需求来源
用户在 AI 修改确认后遇到两个问题:
1. 点击「确认并写入报告」后Ctrl+Z 撤销按钮无法撤销 AI 的修改
2. AI 替换后的文字字体格式与原有文字不一致(原有宋体 12pt替换后变为浏览器默认字体
## 问题 1Ctrl+Z 撤销失效
**现象**AI 修改确认注入后,按 Ctrl+Z 无法撤销。
**根因分析**
`confirmAiInjection` 使用 `targetContent.innerHTML = newHtml;` 直接修改 DOM 属性。这种方式绕过了浏览器 `contentEditable` 的原生撤销/重做历史栈,导致浏览器无法追踪这次更改。
## 问题 2字体格式不一致
**现象**
- 替换前:`<p style="padding: 0px; font-family: SimSun; font-size: 12pt; line-height: 1.5;">内容</p>`
- 替换后:`<p>内容</p>`(无内联样式,显示为浏览器默认字体)
**根因分析**
大模型严格按照指令返回纯净的 `<p>` 标签,没有内联样式。注入后浏览器使用默认字体渲染,与原有宋体 12pt 不一致。
## 解决方向
1. `confirmAiInjection` 改用 `Range.selectNodeContents` + `document.execCommand('insertHTML')`,让浏览器原生撤销栈记录这次替换
2. `handleAIGenerate` 中对 `cleanHtml` 进行正则替换,给 `<p>` 标签注入标准内联样式