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替换后的文字字体与原有文字完全一致
This commit is contained in:
@@ -957,6 +957,7 @@ export default function ReportEditor() {
|
||||
cleanHtml = cleanHtml.replace(/<br\s*\/?>/gi, '');
|
||||
cleanHtml = cleanHtml.replace(/<\/p>\s*<p>/gi, '</p><p>');
|
||||
cleanHtml = cleanHtml.trim();
|
||||
cleanHtml = cleanHtml.replace(/<p>/gi, '<p style="padding: 0px; font-family: SimSun; font-size: 12pt; line-height: 1.5;">');
|
||||
if (targetRegionEl) {
|
||||
setDiffModal({
|
||||
isOpen: true,
|
||||
@@ -982,7 +983,13 @@ export default function ReportEditor() {
|
||||
if (!editorRef.current) return;
|
||||
const targetContent = editorRef.current.querySelector(`.ai-region[data-ai-id="${regionId}"] .ai-content`) as HTMLElement;
|
||||
if (targetContent) {
|
||||
targetContent.innerHTML = newHtml;
|
||||
targetContent.focus();
|
||||
const sel = window.getSelection();
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(targetContent);
|
||||
sel?.removeAllRanges();
|
||||
sel?.addRange(range);
|
||||
document.execCommand('insertHTML', false, newHtml);
|
||||
targetContent.style.transition = 'background-color 0.3s ease';
|
||||
targetContent.style.backgroundColor = '#bfdbfe';
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user