mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 10:06:17 +08:00
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:
@@ -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);
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user