fix(editor): shape tool should be the last used shape (#12425)

Close [BS-3305](https://linear.app/affine-design/issue/BS-3305/白板按s应该使用上次的shape形状)

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

- **New Features**
  - Added a method to cycle through shape types when using the shape tool.

- **Bug Fixes**
  - Improved shape tool behavior to ensure the selected shape type does not change unexpectedly after adding a new shape.

- **Tests**
  - Added an end-to-end test to verify that the shape tool retains the selected shape type after adding a new shape.
  - Enhanced shortcut tests to verify cycling shapes forward and backward using 's' and 'Shift+s' keys.

- **Refactor**
  - Streamlined the logic for cycling through shape types and connector modes for improved maintainability.
  - Removed external utility for cycling shapes, integrating the functionality directly into the shape tool.
  - Updated keyboard shortcut handling to use the new cycling method within the shape tool.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
L-Sun
2025-05-23 16:31:01 +00:00
parent 3f753eddf5
commit 7223d35c89
8 changed files with 83 additions and 45 deletions

View File

@@ -2,6 +2,7 @@ import { expect, type Page } from '@playwright/test';
import { lightThemeV2 } from '@toeverything/theme/v2';
import {
assertEdgelessShapeType,
assertEdgelessTool,
changeShapeFillColor,
changeShapeFillColorToTransparent,
@@ -788,3 +789,21 @@ test('shape should be editable when re-enter canvas', async ({ page }) => {
await dblclickView(page, [50, 50]);
await expect(page.locator('edgeless-shape-text-editor')).toBeAttached();
});
test('shape tool should not be changed after adding new shape', async ({
page,
}) => {
await enterPlaygroundRoom(page);
await initEmptyEdgelessState(page);
await switchEditorMode(page);
await setEdgelessTool(page, 'shape');
await page.keyboard.press('s');
await waitNextFrame(page);
await assertEdgelessShapeType(page, 'ellipse');
await clickView(page, [0, 0]);
await page.keyboard.press('s');
await waitNextFrame(page);
await assertEdgelessShapeType(page, 'ellipse');
});

View File

@@ -86,9 +86,14 @@ test('toggle shapes shortcut', async ({ page }) => {
'roundedRect',
] as ShapeName[];
for (const shape of shapesInOrder) {
await page.keyboard.press('Shift+s');
await page.keyboard.press('s');
await assertEdgelessShapeType(page, shape);
}
for (const shape of shapesInOrder.reverse()) {
await assertEdgelessShapeType(page, shape);
await page.keyboard.press('Shift+s');
}
});
test('should not switch shapes in editing', async ({ page }) => {