Sync inserted AI regions immediately

- Track report editor AI regions in React state instead of only scanning contentEditable DOM during render.

- Observe editor AI region mutations and refresh the AI writing target dropdown without requiring page navigation or refresh.

- Select newly inserted AI regions immediately after insertion and keep a live DOM fallback for generation.

- Harden AI region insertion so it still appends the region if execCommand has no active editor selection.

- Escape AI region names before injecting template HTML and add an accessible label for the insert button.

- Add Playwright coverage for inserting an AI region and seeing it immediately in the AI writing dropdown.

- Update report editor, feature, progress, testing, and AGENTS documentation for AI region synchronization.
This commit is contained in:
2026-05-02 04:08:48 +08:00
parent 5a4056d899
commit 7631ae34ce
7 changed files with 101 additions and 15 deletions

View File

@@ -0,0 +1,25 @@
import { expect, test } from '@playwright/test';
import { loginByApi, uniqueId } from './helpers';
test('newly inserted AI region appears in the AI writing target dropdown immediately', async ({ page }) => {
await loginByApi(page, '0001');
const regionName = `AI区域${uniqueId('region')}`;
page.on('dialog', async (dialog) => {
if (dialog.type() === 'prompt') {
await dialog.accept(regionName);
return;
}
await dialog.accept();
});
await page.goto('/report-editor');
await page.getByTitle('插入AI可编辑区域').click();
await page.getByRole('button', { name: 'AI撰写' }).click();
const aiRegionSelect = page.locator('select').filter({
has: page.locator('option', { hasText: regionName }),
});
await expect(aiRegionSelect).toHaveValue(regionName);
await expect(page.locator('select option', { hasText: regionName })).toHaveCount(1);
});