feat: support snap when resizing element (#12563)

Fixes [BS-2753](https://linear.app/affine-design/issue/BS-2753/)

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

- **New Features**
  - Added snapping support when resizing elements, improving alignment and precision during resize operations.
  - Introduced new resize event handlers allowing extensions to customize resize behavior with start, move, and end callbacks.

- **Bug Fixes**
  - Improved handling of snapping state to prevent errors during drag and resize actions.

- **Tests**
  - Updated resizing tests to ensure consistent snapping behavior by removing default elements that could interfere with test results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
doouding
2025-05-28 02:47:01 +00:00
parent f5f959692a
commit cf456c888f
6 changed files with 253 additions and 34 deletions

View File

@@ -1,13 +1,16 @@
import {
selectElementInEdgeless,
switchEditorMode,
zoomResetByKeyboard,
} from '../utils/actions/edgeless.js';
import {
addBasicBrushElement,
addBasicRectShapeElement,
clickView,
dragBetweenCoords,
enterPlaygroundRoom,
initEmptyEdgelessState,
pressBackspace,
resizeElementByHandle,
} from '../utils/actions/index.js';
import {
@@ -19,10 +22,15 @@ import { test } from '../utils/playwright.js';
test.describe('resizing shapes and aspect ratio will be maintained', () => {
test('positive adjustment', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyEdgelessState(page);
const { noteId } = await initEmptyEdgelessState(page);
await switchEditorMode(page);
await zoomResetByKeyboard(page);
// delete note to avoid snapping to it
await clickView(page, [0, 0]);
await selectElementInEdgeless(page, [noteId]);
await pressBackspace(page);
await addBasicBrushElement(page, { x: 100, y: 100 }, { x: 200, y: 200 });
await page.mouse.click(110, 110);
await assertEdgelessSelectedRect(page, [98, 98, 104, 104]);
@@ -50,10 +58,15 @@ test.describe('resizing shapes and aspect ratio will be maintained', () => {
test('negative adjustment', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyEdgelessState(page);
const { noteId } = await initEmptyEdgelessState(page);
await switchEditorMode(page);
await zoomResetByKeyboard(page);
// delete note to avoid snapping to it
await clickView(page, [0, 0]);
await selectElementInEdgeless(page, [noteId]);
await pressBackspace(page);
await addBasicBrushElement(page, { x: 100, y: 100 }, { x: 200, y: 200 });
await page.mouse.click(110, 110);
await assertEdgelessSelectedRect(page, [98, 98, 104, 104]);