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
@@ -2,7 +2,7 @@ import type { ServiceIdentifier } from '@blocksuite/global/di';
import { DisposableGroup } from '@blocksuite/global/disposable';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { IBound, IPoint } from '@blocksuite/global/gfx';
import { Signal } from '@preact/signals-core';
import { computed, Signal } from '@preact/signals-core';
import { Subject } from 'rxjs';
import type { PointerEventState } from '../../event/index.js';
@@ -125,6 +125,18 @@ export class ToolController extends GfxExtension {
y: 0,
});
readonly lastMouseModelPos$ = computed(() => {
const [x, y] = this.gfx.viewport.toModelCoord(
this.lastMousePos$.value.x,
this.lastMousePos$.value.y
);
return {
x,
y,
};
});
get currentTool$() {
// oxlint-disable-next-line typescript/no-this-alias
const self = this;
@@ -330,6 +342,10 @@ export class ToolController extends GfxExtension {
w: 0,
h: 0,
};
this.lastMousePos$.value = {
x: evt.x,
y: evt.y,
};
// this means the dragEnd event is not even fired
// so we need to manually call the dragEnd method
@@ -372,6 +388,11 @@ export class ToolController extends GfxExtension {
endY: evt.y,
};
this.lastMousePos$.value = {
x: evt.x,
y: evt.y,
};
invokeToolHandler('dragMove', evt, dragContext?.tool);
})
);