fix(core): right click on edgeless will also damage other functions (#13466)
Close [AI-411](https://linear.app/affine-design/issue/AI-411) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Bug Fixes - Releasing the mouse now always ends panning, preventing stuck states. - Actions cancel correctly when you release without dragging. - Refactor - More consistent Copilot activation: use right-click or Ctrl (⌘ on Mac) + left-click. - Smoother switching to Copilot with improved drag-state reset and cleanup. - Removed automatic restoration of previous selection when activating Copilot. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -100,8 +100,8 @@ export class PanTool extends BaseTool<PanToolOption> {
|
|||||||
const dispose = on(document, 'pointerup', evt => {
|
const dispose = on(document, 'pointerup', evt => {
|
||||||
if (evt.button === MouseButton.MIDDLE) {
|
if (evt.button === MouseButton.MIDDLE) {
|
||||||
restoreToPrevious();
|
restoreToPrevious();
|
||||||
dispose();
|
|
||||||
}
|
}
|
||||||
|
dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
type GfxModel,
|
type GfxModel,
|
||||||
MouseButton,
|
MouseButton,
|
||||||
} from '@blocksuite/affine/std/gfx';
|
} from '@blocksuite/affine/std/gfx';
|
||||||
|
import { on } from '@blocksuite/affine-shared/utils';
|
||||||
|
import { isEqual } from 'lodash-es';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -59,24 +61,24 @@ export class CopilotTool extends BaseTool {
|
|||||||
return this.gfx.selection.selectedElements;
|
return this.gfx.selection.selectedElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _initDragState(e: PointerEventState) {
|
private initDragState(e: PointerEventState) {
|
||||||
this.dragStartPoint = this.gfx.viewport.toModelCoord(e.x, e.y);
|
this.dragStartPoint = this.gfx.viewport.toModelCoord(e.x, e.y);
|
||||||
this.dragLastPoint = this.dragStartPoint;
|
this.dragLastPoint = this.dragStartPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
abort() {
|
private clearDragState() {
|
||||||
this._dragging = false;
|
this._dragging = false;
|
||||||
this.dragStartPoint = [0, 0];
|
this.dragStartPoint = [0, 0];
|
||||||
this.dragLastPoint = [0, 0];
|
this.dragLastPoint = [0, 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
abort() {
|
||||||
|
this.clearDragState();
|
||||||
this.gfx.tool.setTool(DefaultTool);
|
this.gfx.tool.setTool(DefaultTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
override activate(): void {
|
override activate(): void {
|
||||||
this.gfx.viewport.locked = true;
|
this.gfx.viewport.locked = true;
|
||||||
|
|
||||||
if (this.gfx.selection.lastSurfaceSelections) {
|
|
||||||
this.gfx.selection.set(this.gfx.selection.lastSurfaceSelections);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override deactivate(): void {
|
override deactivate(): void {
|
||||||
@@ -116,20 +118,25 @@ export class CopilotTool extends BaseTool {
|
|||||||
override dragStart(e: PointerEventState): void {
|
override dragStart(e: PointerEventState): void {
|
||||||
if (this.processing) return;
|
if (this.processing) return;
|
||||||
|
|
||||||
this._initDragState(e);
|
this.initDragState(e);
|
||||||
this._dragging = true;
|
this._dragging = true;
|
||||||
this.draggingAreaUpdated.next();
|
this.draggingAreaUpdated.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
override mounted(): void {
|
override mounted(): void {
|
||||||
this.addHook('pointerDown', evt => {
|
this.addHook('pointerDown', downEvent => {
|
||||||
const useCopilot =
|
const dispose = on(document, 'pointerup', upEvent => {
|
||||||
evt.raw.button === MouseButton.SECONDARY ||
|
if (
|
||||||
(evt.raw.button === MouseButton.MAIN && IS_MAC
|
this.isUseCopilot(upEvent) &&
|
||||||
? evt.raw.metaKey
|
isEqual(this.dragStartPoint, this.dragLastPoint)
|
||||||
: evt.raw.ctrlKey);
|
) {
|
||||||
|
this.abort();
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
|
||||||
if (useCopilot) {
|
if (this.isUseCopilot(downEvent.raw)) {
|
||||||
|
this.clearDragState();
|
||||||
this.controller.setTool(CopilotTool);
|
this.controller.setTool(CopilotTool);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -147,6 +154,15 @@ export class CopilotTool extends BaseTool {
|
|||||||
this.gfx.tool.setTool(DefaultTool);
|
this.gfx.tool.setTool(DefaultTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isUseCopilot(event: PointerEvent) {
|
||||||
|
return (
|
||||||
|
event.button === MouseButton.SECONDARY ||
|
||||||
|
(event.button === MouseButton.MAIN && IS_MAC
|
||||||
|
? event.metaKey
|
||||||
|
: event.ctrlKey)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
updateDragPointsWith(selectedElements: GfxModel[], padding = 0) {
|
updateDragPointsWith(selectedElements: GfxModel[], padding = 0) {
|
||||||
const bounds = getCommonBoundWithRotation(selectedElements).expand(
|
const bounds = getCommonBoundWithRotation(selectedElements).expand(
|
||||||
padding / this.gfx.viewport.zoom
|
padding / this.gfx.viewport.zoom
|
||||||
|
|||||||
Reference in New Issue
Block a user