From df8d1320f50071f7b925da595d2ce26d8f2bb427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Mon, 27 Jul 2026 16:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B4=A0=E6=9D=90=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E9=80=89=E6=8B=A9=E6=9D=A5=E6=BA=90=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据 click detail 识别键盘激活并提前清理残留指针类型 新增触摸手势后键盘选择的回归测试 --- .../ImageCanvasAssetRowView.test.tsx | 16 ++++++++++++++++ .../image-editor/ImageCanvasAssetRowView.tsx | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/image-editor/ImageCanvasAssetRowView.test.tsx b/src/components/image-editor/ImageCanvasAssetRowView.test.tsx index 907f160b5..fe69f5845 100644 --- a/src/components/image-editor/ImageCanvasAssetRowView.test.tsx +++ b/src/components/image-editor/ImageCanvasAssetRowView.test.tsx @@ -227,6 +227,22 @@ describe('ImageCanvasAssetRowView', () => { ); }); + it('uses click detail to recognize keyboard selection after a stale touch gesture', () => { + const toggleAssetSelected = vi.fn(); + renderAssetRow({ isAssetSelectionMode: true, toggleAssetSelected }); + const primaryButton = screen.getByRole('button', { + name: '选择素材账号素材A', + }); + + fireEvent.pointerDown(primaryButton, { pointerType: 'touch' }); + fireEvent.click(primaryButton, { detail: 0 }); + + expect(toggleAssetSelected).toHaveBeenCalledWith( + 'asset-1', + expect.objectContaining({ pointerKind: 'keyboard' }), + ); + }); + it('renders rename input and commits with Enter', () => { const commitAssetRename = vi.fn(); renderAssetRow({ diff --git a/src/components/image-editor/ImageCanvasAssetRowView.tsx b/src/components/image-editor/ImageCanvasAssetRowView.tsx index 6d4350637..ef8a067c0 100644 --- a/src/components/image-editor/ImageCanvasAssetRowView.tsx +++ b/src/components/image-editor/ImageCanvasAssetRowView.tsx @@ -109,6 +109,9 @@ export function ImageCanvasAssetRowView({ const selectAssetFromEvent = useCallback( (event: ReactMouseEvent) => { + const pointerKind = + event.detail === 0 ? 'keyboard' : selectionPointerKindRef.current; + selectionPointerKindRef.current = 'keyboard'; if ( !isAssetSelectionMode || isUploadingAsset || @@ -123,9 +126,8 @@ export function ImageCanvasAssetRowView({ shiftKey: event.shiftKey, ctrlKey: event.ctrlKey, metaKey: event.metaKey, - pointerKind: selectionPointerKindRef.current, + pointerKind, }); - selectionPointerKindRef.current = 'keyboard'; }, [ asset.id,