Skip to content

Commit

Permalink
fix(edgeless): root of mindmap may be invalid during delting (#8227)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Sun committed Sep 8, 2024
1 parent 65991ec commit d46177c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/affine/block-surface/src/element-model/mindmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
const nodesMap = this.children;

// The element may be removed
if (!nodesMap) {
if (!nodesMap || nodesMap.size === 0) {
this._nodeMap = mindmapNodeMap;
// @ts-ignore
this._tree = null;
Expand Down
39 changes: 38 additions & 1 deletion tests/edgeless/mindmap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { expect } from '@playwright/test';
import { clickView } from 'utils/actions/click.js';
import {
addBasicRectShapeElement,
autoFit,
edgelessCommonSetup,
getSelectedBound,
getSelectedBoundCount,
zoomResetByKeyboard,
} from 'utils/actions/edgeless.js';
import { assertEdgelessSelectedRect } from 'utils/asserts.js';
import {
pressBackspace,
selectAllByKeyboard,
undoByKeyboard,
} from 'utils/actions/keyboard.js';
import {
assertEdgelessSelectedRect,
assertSelectedBound,
} from 'utils/asserts.js';

import { test } from '../utils/playwright.js';

Expand All @@ -22,3 +35,27 @@ test('elements should be selectable after open mindmap menu', async ({
await page.mouse.click(start.x + 5, start.y + 5);
await assertEdgelessSelectedRect(page, [100, 100, 100, 100]);
});

test('undo deletion of mindmap should restore the deleted element', async ({
page,
}) => {
await edgelessCommonSetup(page);
await zoomResetByKeyboard(page);

await page.keyboard.press('m');
await clickView(page, [0, 0]);
await autoFit(page);

await selectAllByKeyboard(page);
const mindmapBound = await getSelectedBound(page);

await pressBackspace(page);

await selectAllByKeyboard(page);
expect(await getSelectedBoundCount(page)).toBe(0);

await undoByKeyboard(page);

await selectAllByKeyboard(page);
await assertSelectedBound(page, mindmapBound);
});
2 changes: 2 additions & 0 deletions tests/utils/actions/edgeless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
enterPlaygroundRoom,
getEditorLocator,
initEmptyEdgelessState,
resetHistory,
waitNextFrame,
} from './misc.js';

Expand Down Expand Up @@ -1707,6 +1708,7 @@ export async function edgelessCommonSetup(page: Page) {
await initEmptyEdgelessState(page);
await switchEditorMode(page);
await deleteAll(page);
await resetHistory(page);
}

export async function createFrame(
Expand Down

0 comments on commit d46177c

Please sign in to comment.