From e296fc097914789c6098e670f5390b8f9f5bc27a Mon Sep 17 00:00:00 2001 From: clawdbot Date: Wed, 28 Jan 2026 22:10:34 +0800 Subject: [PATCH] refactor: centralize selection key helper --- packages/editor/src/editor/Canvas.tsx | 7 +------ packages/editor/src/editor/ContextMenu.tsx | 6 +----- packages/editor/src/editor/selection.ts | 5 +++++ 3 files changed, 7 insertions(+), 11 deletions(-) create mode 100644 packages/editor/src/editor/selection.ts diff --git a/packages/editor/src/editor/Canvas.tsx b/packages/editor/src/editor/Canvas.tsx index baac35f..b376ef1 100644 --- a/packages/editor/src/editor/Canvas.tsx +++ b/packages/editor/src/editor/Canvas.tsx @@ -5,6 +5,7 @@ import { Button, Space } from 'antd'; import type { ResizeHandle } from './types'; import { rectFromPoints } from './geometry'; import type { ContextMenuState } from './ContextMenu'; +import { selectionKeyOf } from './selection'; export interface CanvasProps { screen: Screen; @@ -40,12 +41,6 @@ function isPrimaryButton(e: React.PointerEvent | PointerEvent): boolean { return (e as PointerEvent).buttons === 1 || (e as PointerEvent).button === 0; } -function selectionKeyOf(ids: string[]): string { - // Keep stable regardless of selection order. - // This avoids false mismatches between context-menu state and reducer state. - return [...ids].sort().join('|'); -} - export function Canvas(props: CanvasProps) { const ref = useRef(null); const [box, setBox] = useState<{ x1: number; y1: number; x2: number; y2: number } | null>(null); diff --git a/packages/editor/src/editor/ContextMenu.tsx b/packages/editor/src/editor/ContextMenu.tsx index b550d63..81cb712 100644 --- a/packages/editor/src/editor/ContextMenu.tsx +++ b/packages/editor/src/editor/ContextMenu.tsx @@ -1,11 +1,7 @@ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import { Typography } from 'antd'; -function selectionKeyOf(ids: string[]): string { - // Keep stable regardless of selection order. - // This avoids false mismatches between context-menu state and reducer state. - return [...ids].sort().join('|'); -} +import { selectionKeyOf } from './selection'; export type ContextMenuState = | { diff --git a/packages/editor/src/editor/selection.ts b/packages/editor/src/editor/selection.ts new file mode 100644 index 0000000..0bbe654 --- /dev/null +++ b/packages/editor/src/editor/selection.ts @@ -0,0 +1,5 @@ +export function selectionKeyOf(ids: string[]): string { + // Keep stable regardless of selection order. + // This avoids false mismatches between context-menu state and reducer state. + return [...ids].sort().join('|'); +}