Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: cannot exit editing mode when click frame body (#11603)

doouding714f2e79dcb4
diff --git a/blocksuite/affine/blocks/edgeless-text/src/edgeless-text-block.ts b/blocksuite/affine/blocks/edgeless-text/src/edgeless-text-block.ts
index d8e37a0f66..d161247a40 100644
--- a/blocksuite/affine/blocks/edgeless-text/src/edgeless-text-block.ts
+++ b/blocksuite/affine/blocks/edgeless-text/src/edgeless-text-block.ts
@@ -259,7 +259,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
};
}
- override onSelected(context: SelectedContext) {
+ override onSelected(context: SelectedContext): void | boolean {
const { selected, multiSelect, event: e } = context;
const { editing } = this.gfx.selection;
const alreadySelected = this.gfx.selection.has(this.model.id);
@@ -318,7 +318,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
})
.catch(console.error);
} else {
- super.onSelected(context);
+ return super.onSelected(context);
}
}
diff --git a/blocksuite/affine/blocks/frame/src/frame-block.ts b/blocksuite/affine/blocks/frame/src/frame-block.ts
index 5b7415eb11..142a72841f 100644
--- a/blocksuite/affine/blocks/frame/src/frame-block.ts
+++ b/blocksuite/affine/blocks/frame/src/frame-block.ts
@@ -53,7 +53,7 @@ export class FrameBlockComponent extends GfxBlockComponent<FrameBlockModel> {
};
}
- override onSelected(context: SelectedContext): void {
+ override onSelected(context: SelectedContext): boolean | void {
const { x, y } = context.position;
if (
@@ -63,10 +63,10 @@ export class FrameBlockComponent extends GfxBlockComponent<FrameBlockModel> {
// otherwise if the frame has title, then ignore it because in this case the frame cannot be selected by frame body
this.model.props.title.length)
) {
- return;
+ return false;
}
- super.onSelected(context);
+ return super.onSelected(context);
}
override renderGfxBlock() {
diff --git a/blocksuite/framework/std/src/gfx/element-transform/transform-manager.ts b/blocksuite/framework/std/src/gfx/element-transform/transform-manager.ts
index 0c03988807..55e7d4c5ac 100644
--- a/blocksuite/framework/std/src/gfx/element-transform/transform-manager.ts
+++ b/blocksuite/framework/std/src/gfx/element-transform/transform-manager.ts
@@ -115,8 +115,8 @@ export class ElementTransformManager extends GfxExtension {
fallback: lockedElement !== picked,
};
- view?.onSelected(context);
- return true;
+ const selected = view?.onSelected(context);
+ return selected ?? true;
}
return false;
diff --git a/blocksuite/framework/std/src/gfx/view/view.ts b/blocksuite/framework/std/src/gfx/view/view.ts
index a75893034e..f7b8f470b1 100644
--- a/blocksuite/framework/std/src/gfx/view/view.ts
+++ b/blocksuite/framework/std/src/gfx/view/view.ts
@@ -193,13 +193,15 @@ export class GfxElementModelView<
this.model.xywh = currentBound.moveDelta(dx, dy).serialize();
}
- onSelected(context: SelectedContext) {
+ onSelected(context: SelectedContext): void | boolean {
if (this.model instanceof GfxPrimitiveElementModel) {
if (context.multiSelect) {
this.gfx.selection.toggle(this.model);
} else {
this.gfx.selection.set({ elements: [this.model.id] });
}
+
+ return true;
}
}
diff --git a/blocksuite/framework/std/src/view/element/gfx-block-component.ts b/blocksuite/framework/std/src/view/element/gfx-block-component.ts
index 0b514f7e28..1d4eee375b 100644
--- a/blocksuite/framework/std/src/view/element/gfx-block-component.ts
+++ b/blocksuite/framework/std/src/view/element/gfx-block-component.ts
@@ -103,12 +103,14 @@ export abstract class GfxBlockComponent<
this.model.pop('xywh');
}
- onSelected(context: SelectedContext) {
+ onSelected(context: SelectedContext): void | boolean {
if (context.multiSelect) {
this.gfx.selection.toggle(this.model);
} else {
this.gfx.selection.set({ elements: [this.model.id] });
}
+
+ return true;
}
onRotate() {}
@@ -219,12 +221,14 @@ export function toGfxBlockComponent<
}
// eslint-disable-next-line sonarjs/no-identical-functions
- onSelected(context: SelectedContext) {
+ onSelected(context: SelectedContext): void | boolean {
if (context.multiSelect) {
this.gfx.selection.toggle(this.model);
} else {
this.gfx.selection.set({ elements: [this.model.id] });
}
+
+ return true;
}
onRotate() {}
diff --git a/tests/affine-local/e2e/blocksuite/clipboard/clipboard.spec.ts b/tests/affine-local/e2e/blocksuite/clipboard/clipboard.spec.ts
index 5e520da39a..538287fa9d 100644
--- a/tests/affine-local/e2e/blocksuite/clipboard/clipboard.spec.ts
+++ b/tests/affine-local/e2e/blocksuite/clipboard/clipboard.spec.ts
@@ -184,7 +184,7 @@ test('paste surface-ref block to another doc as embed-linked-doc block', async (
// add a shape
await page.keyboard.press('s');
// click to add a shape
- await container.click({ position: { x: 100, y: 500 } });
+ await container.click({ position: { x: 100, y: 300 } });
await page.waitForTimeout(50);
// add a frame
await page.keyboard.press('f');