feat(canvas): 框选 - 新增工具栏「框选」工具,空白处拖动框选后自动回到移动与选择 (#78)

Co-authored-by: sikongyue <3155157671@qq.com>
This commit is contained in:
爱笑的毛毛虫
2026-08-02 14:40:20 +08:00
committed by GitHub
parent f5c6c3a80f
commit 0317ac5bc7
6 changed files with 24 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ type UseCanvasSelectionControllerOptions = {
onNodeInteractionStart: (selectionModifier: boolean) => void;
onNodeClick: (node: CanvasNodeData) => void;
onDeselect: () => void;
onSelectionBoxEnd?: () => void;
};
type DragState = {
@@ -57,6 +58,7 @@ export function useCanvasSelectionController({
onNodeInteractionStart,
onNodeClick,
onDeselect,
onSelectionBoxEnd,
}: UseCanvasSelectionControllerOptions) {
const dragFrameRef = useRef<number | null>(null);
const pendingNodeDragRef = useRef<Position>({ x: 0, y: 0 });
@@ -296,7 +298,8 @@ export function useCanvasSelectionController({
const wasSelection = selectionActivatedRef.current;
cancelSelectionBox();
if (hadPendingSelection && !wasSelection) deselectCanvas();
}, [cancelSelectionBox, deselectCanvas]);
if (hadPendingSelection) onSelectionBoxEnd?.();
}, [cancelSelectionBox, deselectCanvas, onSelectionBoxEnd]);
useEffect(() => {
const handleMouseUp = (event: MouseEvent) => {