mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 01:49:51 +08:00
6170a90785
Add a persistent "Show line numbers in code blocks" setting to Editor Settings that controls line-number visibility across all code blocks. Individual blocks can still override the global default via the per-block More menu toggle. ## Changes - **schema.ts** - add `codeBlockLineNumbers: z.boolean().default(true)` to `AffineEditorSettingSchema` - **code-block.ts** - read `codeBlockLineNumbers` from `EditorSettingProvider` reactively via a stable `signal(true)` updated by `effect()` in `connectedCallback`; expose `showLineNumbers` getter as single source of truth used by both `renderBlock()` and the toolbar - **config.ts** - toolbar line-number toggle reads `blockComponent.showLineNumbers` (resolved state) instead of `model.props.lineNumber ?? true` - **general.tsx** - add `DefaultCodeBlockLineNumberSettings` Switch row in editor general settings - **en.json + i18n.gen.ts** - add i18n strings for the new setting - **line-numbers.spec.ts** - add 7 e2e tests covering default visibility, global toggle on/off, per-block override in both directions, multi-block, newly created blocks, and persistence across reload ## Behaviour | State | Result | |---|---| | Global ON (default), no per-block override | Line numbers shown | | Global OFF, no per-block override | Line numbers hidden | | Global OFF, per-block explicitly ON | Line numbers shown | | Global ON, per-block explicitly OFF | Line numbers hidden | | Mobile (feature flag) | Always hidden regardless of settings | ## Notes - Existing per-block toggle behaviour is fully preserved and unchanged - Default is `true` so no regression for existing users - The blocksuite-side reads `codeBlockLineNumbers` via a type cast (`as Record<string, unknown>`) because the key lives in the AFFiNE-level `EditorSettingSchema`, not in blocksuite's own `GeneralSettingSchema` - this is an intentional architectural boundary Closes #14965 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a global setting to show or hide line numbers in code blocks by default. * Added localized title and description text for the new setting. * Preserved per-code-block overrides through the block’s More menu. * **Bug Fixes** * Line-number visibility now stays consistent across existing and newly created code blocks, including after reloads. * **Tests** * Added end-to-end coverage for defaults, overrides, persistence, and multiple code blocks. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
|
import {
|
|
addCodeBlock,
|
|
clickNewPageButton,
|
|
waitForEditorLoad,
|
|
} from '@affine-test/kit/utils/page-logic';
|
|
import type { Page } from '@playwright/test';
|
|
|
|
export const gotoContentFromTitle = async (page: Page) => {
|
|
await page.keyboard.press('Enter');
|
|
};
|
|
|
|
export const createNewPage = async (page: Page) => {
|
|
await clickNewPageButton(page);
|
|
};
|
|
|
|
export const initCodeBlockByOneStep = async (page: Page) => {
|
|
await openHomePage(page);
|
|
await createNewPage(page);
|
|
await waitForEditorLoad(page);
|
|
await gotoContentFromTitle(page);
|
|
await addCodeBlock(page);
|
|
};
|
|
|
|
/**
|
|
* Opens the "More" menu on the first code block and returns locators for
|
|
* the line-number toggle buttons inside it.
|
|
* Uses .first() to stay deterministic when multiple code blocks are present.
|
|
*/
|
|
export const openCodeBlockMoreMenu = async (page: Page) => {
|
|
const codeBlock = page.locator('affine-code').first();
|
|
await codeBlock.hover();
|
|
|
|
const moreButton = page
|
|
.locator('affine-code-toolbar')
|
|
.getByRole('button', { name: 'More' });
|
|
await moreButton.click();
|
|
|
|
const menu = page.locator('.more-popup-menu');
|
|
const lineNumberButton = menu.getByRole('button', { name: 'Line number' });
|
|
const cancelLineNumberButton = menu.getByRole('button', {
|
|
name: 'Cancel line number',
|
|
});
|
|
|
|
return { menu, lineNumberButton, cancelLineNumberButton };
|
|
};
|