Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(core): disable space ai guidance for non-paragraph block (#11847)

yoyoyohamapif65c8f8fa69a
diff --git a/packages/frontend/core/src/blocksuite/ai/entries/space/setup-space.ts b/packages/frontend/core/src/blocksuite/ai/entries/space/setup-space.ts
index 8d1a414cd6..e80a93214f 100644
--- a/packages/frontend/core/src/blocksuite/ai/entries/space/setup-space.ts
+++ b/packages/frontend/core/src/blocksuite/ai/entries/space/setup-space.ts
@@ -27,7 +27,12 @@ export function setupSpaceAIEntry(panel: AffineAIPanelWidget) {
const selection = host.selection.find(TextSelection);
if (selection && selection.isCollapsed() && selection.from.index === 0) {
const block = host.view.getBlock(selection.blockId);
- if (!block?.model?.text || block.model.text?.length > 0) return;
+ if (
+ !block?.model?.text ||
+ block.model.text?.length > 0 ||
+ block.model.flavour !== 'affine:paragraph'
+ )
+ return;
event.preventDefault();
handleInlineAskAIAction(host);
diff --git a/tests/affine-cloud-copilot/e2e/basic/guidance.spec.ts b/tests/affine-cloud-copilot/e2e/basic/guidance.spec.ts
index d79342d5c0..6bbd41bb3d 100644
--- a/tests/affine-cloud-copilot/e2e/basic/guidance.spec.ts
+++ b/tests/affine-cloud-copilot/e2e/basic/guidance.spec.ts
@@ -15,4 +15,24 @@ test.describe('AIBasic/Guidance', () => {
await page.keyboard.press('Space');
await expect(page.locator('affine-ai-panel-widget')).toBeVisible();
});
+
+ test('should not show AI panel when space is pressed on non-empty paragraph', async ({
+ page,
+ utils,
+ }) => {
+ await utils.editor.focusToEditor(page);
+ await page.keyboard.insertText('HelloWorld');
+ await page.keyboard.press('Space');
+ await expect(page.locator('affine-ai-panel-widget')).not.toBeVisible();
+ });
+
+ test('should not show AI panel when space is pressed on non-paragraph block', async ({
+ page,
+ utils,
+ }) => {
+ await utils.editor.focusToEditor(page);
+ await page.keyboard.insertText('```js');
+ await page.keyboard.press('Enter');
+ await expect(page.locator('affine-ai-panel-widget')).not.toBeVisible();
+ });
});