fix(core): cannot input space at the beginning of a blank paragraph (#12166)

### TL:DR

fix: cannot input space at the beginning of a blank paragraph

> CLOSE BS-3427

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Improved space key handling in the editor: pressing space on an empty AI input now hides the AI panel and inserts a space character back into the editor.

- **Bug Fixes**
  - Prevented the AI panel from processing empty input when space is pressed, ensuring smoother user experience.

- **Tests**
  - Added an end-to-end test verifying that pressing space on an empty AI input hides the AI panel and inserts a space.

- **Refactor**
  - Streamlined event handling logic for space key detection in the editor.

- **Chores**
  - Enhanced editor content retrieval to optionally preserve whitespace while removing invisible characters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
yoyoyohamapi
2025-05-07 07:46:13 +00:00
parent 267bb3a975
commit 8ea39d5438
3 changed files with 63 additions and 9 deletions

View File

@@ -35,4 +35,20 @@ test.describe('AIBasic/Guidance', () => {
await page.keyboard.press('Enter');
await expect(page.locator('affine-ai-panel-widget')).not.toBeVisible();
});
test('should hide AI panel and insert space back to editor when space is pressed on empty input', async ({
page,
utils,
}) => {
await utils.editor.focusToEditor(page);
await page.keyboard.press('Space');
await expect(page.locator('affine-ai-panel-widget')).toBeVisible();
await page.keyboard.press('Space');
await expect(page.locator('affine-ai-panel-widget')).not.toBeVisible();
await expect(async () => {
const content = await utils.editor.getEditorContent(page, false);
expect(content).toBe(' ');
}).toPass({ timeout: 5000 });
});
});