mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-21 03:03:15 +08:00
## Summary - Search language IDs, display labels, and aliases case-insensitively, preserving prefix matching and the existing result order. - Ignore pending grammar-load results when the selected language has changed, preventing highlighting from returning after switching to Plain Text. Related to #15492: display-label matching will also make “Plain Text” searchable by its full name, while the highlighting fix prevents pending language loads from restoring highlighting after switching to Plain Text. ## Validation Code-block E2E suite (7 passed), scoped TypeScript checks, lint, and formatting checks passed. Both focused regression tests fail on unmodified `canary` and pass with the fixes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Code block language search now matches display names, IDs, aliases, and labels without regard to letter case. - Search results prioritize matches at the beginning of language names and aliases over label-only matches. - **Bug Fixes** - Prevented outdated syntax highlighting from appearing after a code block language is changed or cleared while loading. - Prevented duplicate language-loading requests during concurrent highlighting updates. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: DarkSky <darksky2048@gmail.com>
116 lines
3.2 KiB
TypeScript
116 lines
3.2 KiB
TypeScript
import { test } from '@affine-test/kit/playwright';
|
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
|
import { type, waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
|
|
import { expect } from '@playwright/test';
|
|
|
|
import {
|
|
createNewPage,
|
|
gotoContentFromTitle,
|
|
initCodeBlockByOneStep,
|
|
} from './utils';
|
|
|
|
test.describe('Code Block Autocomplete Operations', () => {
|
|
test('angle brackets are not supported', async ({ page }) => {
|
|
// open the home page and insert the code block
|
|
await initCodeBlockByOneStep(page);
|
|
await page.keyboard.type('<');
|
|
const codeUnit = page.locator('affine-code-unit');
|
|
await expect(codeUnit).toHaveText('<');
|
|
});
|
|
});
|
|
|
|
test.describe('Code Block Preview', () => {
|
|
test('enable html preview', async ({ page }) => {
|
|
const code = page.locator('affine-code');
|
|
|
|
await openHomePage(page);
|
|
await createNewPage(page);
|
|
await waitForEditorLoad(page);
|
|
await gotoContentFromTitle(page);
|
|
await type(page, '```html aaa');
|
|
await code.hover({
|
|
position: {
|
|
x: 155,
|
|
y: 65,
|
|
},
|
|
});
|
|
await page.getByText('Preview').click();
|
|
await expect(
|
|
page
|
|
.locator('iframe[title="HTML Preview"]')
|
|
.contentFrame()
|
|
.getByText('aaa')
|
|
).toBeVisible();
|
|
});
|
|
|
|
test('enable mermaid preview', async ({ page }) => {
|
|
const code = page.locator('affine-code');
|
|
const mermaidSvg = page.locator('mermaid-preview .mermaid-preview-svg svg');
|
|
|
|
await openHomePage(page);
|
|
await createNewPage(page);
|
|
await waitForEditorLoad(page);
|
|
await gotoContentFromTitle(page);
|
|
await type(page, '```mermaid graph TD;A-->B');
|
|
await code.hover({
|
|
position: {
|
|
x: 155,
|
|
y: 65,
|
|
},
|
|
});
|
|
await page.getByText('Preview').click();
|
|
await expect(mermaidSvg).toBeVisible();
|
|
});
|
|
|
|
test('enable typst preview', async ({ page }) => {
|
|
const code = page.locator('affine-code');
|
|
const typstPreview = page.locator('typst-preview');
|
|
|
|
await openHomePage(page);
|
|
await createNewPage(page);
|
|
await waitForEditorLoad(page);
|
|
await gotoContentFromTitle(page);
|
|
await type(page, '```typst = Title');
|
|
await code.hover({
|
|
position: {
|
|
x: 155,
|
|
y: 65,
|
|
},
|
|
});
|
|
await page.getByText('Preview').click();
|
|
await expect(typstPreview).toBeVisible();
|
|
});
|
|
|
|
test('change lang without preview', async ({ page }) => {
|
|
const code = page.locator('affine-code');
|
|
const preview = page.locator('affine-code .affine-code-block-preview');
|
|
|
|
await openHomePage(page);
|
|
await createNewPage(page);
|
|
await waitForEditorLoad(page);
|
|
await gotoContentFromTitle(page);
|
|
await type(page, '```html aaa');
|
|
|
|
await code.hover({
|
|
position: {
|
|
x: 155,
|
|
y: 65,
|
|
},
|
|
});
|
|
await page.getByText('Preview').click();
|
|
await expect(preview).toBeVisible();
|
|
|
|
// change to lang without preview support
|
|
await page.getByTestId('lang-button').click();
|
|
await page.getByRole('button', { name: 'ABAP' }).click();
|
|
|
|
await expect(preview).toBeHidden();
|
|
|
|
// change back to html
|
|
await page.getByTestId('lang-button').click();
|
|
await page.getByRole('button', { name: 'HTML', exact: true }).click();
|
|
|
|
await expect(preview).toBeVisible();
|
|
});
|
|
});
|