fix(editor): contentEditable回车导致段落溢出.ai-content
- handleAIGenerate中获取currentHtml前增加溢出段落合并逻辑 - 遍历.ai-content之后的兄弟<p>节点,移回.ai-content内 - 合并后同步更新contentRef和saveDraftToStorage - 确保diff弹窗左侧能显示AI可编辑区域内的全部段落
This commit is contained in:
@@ -883,6 +883,23 @@ export default function ReportEditor() {
|
||||
}
|
||||
}
|
||||
const targetRegionEl = editorRef.current?.querySelector(`.ai-region[data-ai-id="${actualTargetId}"] .ai-content`) as HTMLElement | null;
|
||||
// 合并溢出的段落:浏览器 contentEditable 可能在回车时把 <p> 生成到 .ai-content 之外
|
||||
const aiRegion = editorRef.current?.querySelector(`.ai-region[data-ai-id="${actualTargetId}"]`);
|
||||
if (aiRegion && targetRegionEl) {
|
||||
let nextSibling = targetRegionEl.nextElementSibling;
|
||||
while (nextSibling) {
|
||||
const toMove = nextSibling;
|
||||
nextSibling = nextSibling.nextElementSibling;
|
||||
if (toMove.tagName === 'P') {
|
||||
targetRegionEl.appendChild(toMove);
|
||||
}
|
||||
}
|
||||
// 同步更新 contentRef 和草稿
|
||||
if (editorRef.current) {
|
||||
contentRef.current = editorRef.current.innerHTML;
|
||||
saveDraftToStorage();
|
||||
}
|
||||
}
|
||||
const currentHtml = targetRegionEl ? targetRegionEl.innerHTML.replace(/​/g, '').trim() : '';
|
||||
const globalContextText = editorRef.current?.innerText || '';
|
||||
let messageContent: any;
|
||||
|
||||
Reference in New Issue
Block a user