Skip to content

Commit

Permalink
fix(blocks): fix slash menu is triggered in ignored blocks (#8469)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Sun committed Sep 26, 2024
1 parent 5c48661 commit cdeedd4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/blocks/src/root-block/widgets/slash-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
type AffineInlineEditor,
getInlineEditorByModel,
} from '@blocksuite/affine-components/rich-text';
import { getCurrentNativeRange } from '@blocksuite/affine-shared/utils';
import {
getCurrentNativeRange,
matchFlavours,
} from '@blocksuite/affine-shared/utils';
import { WidgetComponent } from '@blocksuite/block-std';
import {
assertExists,
Expand Down Expand Up @@ -154,6 +157,8 @@ export class AffineSlashMenuWidget extends WidgetComponent {
const model = this.host.doc.getBlock(textSelection.blockId)?.model;
if (!model) return;

if (matchFlavours(model, this.config.ignoreBlockTypes)) return;

const inlineRange = inlineEditor.getInlineRange();
if (!inlineRange) return;

Expand Down
13 changes: 13 additions & 0 deletions tests/slash-menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ test.describe('slash menu should show and hide correctly', () => {
});
});

test.describe('slash menu should not be shown in ignored blocks', () => {
test('code block', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyParagraphState(page);
await focusRichText(page);

await type(page, '```');
await pressEnter(page);
await type(page, '/');
await expect(page.locator('.slash-menu')).toBeHidden();
});
});

test('should slash menu works with fast type', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyParagraphState(page);
Expand Down

0 comments on commit cdeedd4

Please sign in to comment.