refactor: default-tool box selection (#11800)

### Changed
- Rewrite box selection in `default-tool`, the view can decide whether to be selected in box selection by return a boolean value in `onBoxSelected` method
- Cleanup unnecessary states in `default-tool` and some naming problem
This commit is contained in:
doouding
2025-04-22 08:18:25 +00:00
parent 1d58792631
commit b59f6ebde0
16 changed files with 209 additions and 150 deletions
+40 -1
View File
@@ -7,8 +7,13 @@ import {
} from '@blocksuite/affine-model';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import { requestThrottledConnectedFrame } from '@blocksuite/affine-shared/utils';
import { Bound } from '@blocksuite/global/gfx';
import type { PointerEventState } from '@blocksuite/std';
import { GfxElementModelView } from '@blocksuite/std/gfx';
import {
type BoxSelectionContext,
GfxElementModelView,
type SelectedContext,
} from '@blocksuite/std/gfx';
import { handleLayout } from './utils.js';
@@ -329,6 +334,40 @@ export class MindMapView extends GfxElementModelView<MindmapElementModel> {
return collapseButton;
}
override onSelected(context: SelectedContext): void | boolean {
const { position } = context;
const target = this.model.childElements.find(child => {
if (child.elementBound.containsPoint([position.x, position.y])) {
return true;
}
return false;
});
if (target) {
if (this.model.isLocked()) {
return super.onSelected(context);
}
if (context.multiSelect) {
this.gfx.selection.toggle(target);
} else {
this.gfx.selection.set({ elements: [target.id] });
}
return true;
}
return false;
}
override onBoxSelected(context: BoxSelectionContext) {
const { box } = context;
const bound = new Bound(box.x, box.y, box.w, box.h);
return bound.contains(this.model.elementBound);
}
override onCreated(): void {
this._setLayoutMethod();
this._initCollapseButtons();