From f3292211a893ac55d38f8e9d79c7d70b78f5d2fa Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Tue, 9 Dec 2025 00:17:16 +0100 Subject: [PATCH] feat: remove unused canvas focus request from tag interactions. --- .../desktop/components/DesktopWorkspace.tsx | 29 ++++++++----------- .../interactions/useTagInteractions.ts | 6 +--- .../panel/useDocumentsContextValues.ts | 7 ++--- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/frontend/src/desktop/components/DesktopWorkspace.tsx b/frontend/src/desktop/components/DesktopWorkspace.tsx index c545dc6..9dc4994 100644 --- a/frontend/src/desktop/components/DesktopWorkspace.tsx +++ b/frontend/src/desktop/components/DesktopWorkspace.tsx @@ -9,7 +9,7 @@ import { LayoutStore, LayoutCard } from '../logic/LayoutSystem'; import DesktopDocumentCard from './DesktopDocumentCard'; import usePreviewMetadata from '../hooks/usePreviewMetadata'; import { - useTagInteractions, + TagInteractionHandlers, } from '../../documents/interactions/useTagInteractions'; import './workspace-layout.css'; import './workspace-items.css'; @@ -22,7 +22,7 @@ import type { DocumentsListEntry, Document } from '../../types/documents'; import { useAppState } from '../../lib/store/appState'; import { useDocumentOpen } from '../../lib/context/DocumentOpenContext'; import { useDocumentsAssetContext } from '../../documents/context/DocumentsAssetContext'; -import { useDocumentsCommandContext } from '../../documents/context/DocumentsCommandContext'; +import { useDocumentsViewStateContext } from '../../documents/context/DocumentsViewStateContext'; interface DocumentSizeInfo { width: number; @@ -41,6 +41,7 @@ interface DesktopWorkspaceProps { onSelectionChange?: (selectedIds: Identifier[]) => void; viewId?: string | null; defaultCardSize?: number; + tagHandlers?: TagInteractionHandlers; } const DesktopWorkspaceContent: React.FC = ({ @@ -48,13 +49,13 @@ const DesktopWorkspaceContent: React.FC = ({ onSelectionChange, viewId, defaultCardSize = 200, + tagHandlers, }) => { const { openDocument } = useDocumentOpen(); const { ensureAssetUrl, getDocumentAsset } = useDocumentsAssetContext(); - const { tags } = useDocumentsCommandContext(); const { tenant } = useAppState(); const tenantId = tenant?.id as Identifier; @@ -181,22 +182,16 @@ const DesktopWorkspaceContent: React.FC = ({ } }, []); - // Tag Interactions - const tagHandlers = useTagInteractions({ - onAssignTagToDocument: (docId: string, tagId: string) => { - tags.onAttach?.(docId, tagId); - }, - onRemoveTagFromDocument: (docId: string, tagId: string) => { - tags.onDetach?.(docId, tagId); - }, - requestCanvasFocus: focusShell, - onTagClick: tags.onClick, - }); + const { scrollRef } = useDocumentsViewStateContext(); useEffect(() => { const handleWindowKeyDown = (e: KeyboardEvent) => { - // Only handle events if the container itself is the target (focused) - if (e.target !== containerRef.current) { + // Handle events if the container or the shared scrollRef is focused + // This allows unified handlers (which focus scrollRef) to work seamlessly with Desktop shortcuts + const isTargetContainer = e.target === containerRef.current; + const isTargetScrollRef = scrollRef && e.target === scrollRef.current; + + if (!isTargetContainer && !isTargetScrollRef) { return; } @@ -318,7 +313,7 @@ const DesktopWorkspaceContent: React.FC = ({ window.addEventListener('keydown', handleWindowKeyDown); return () => window.removeEventListener('keydown', handleWindowKeyDown); - }, [selectedDocumentIds, items, openDocument, layoutStore, handleSelectionChange]); + }, [selectedDocumentIds, items, openDocument, layoutStore, handleSelectionChange, scrollRef]); return ( <> diff --git a/frontend/src/documents/interactions/useTagInteractions.ts b/frontend/src/documents/interactions/useTagInteractions.ts index e0277e1..5c2fcfd 100644 --- a/frontend/src/documents/interactions/useTagInteractions.ts +++ b/frontend/src/documents/interactions/useTagInteractions.ts @@ -47,7 +47,6 @@ const cleanupPreview = (previewNode: HTMLElement | null) => { interface UseTagInteractionsArgs { onAssignTagToDocument?: (docId: Identifier, tagId: Identifier) => void; onRemoveTagFromDocument?: (docId: Identifier, tagId: Identifier) => void; - requestCanvasFocus?: () => void; onTagClick?: (tagId: Identifier) => void; } @@ -69,7 +68,6 @@ export interface TagInteractionHandlers { export const useTagInteractions = ({ onAssignTagToDocument, onRemoveTagFromDocument, - requestCanvasFocus, onTagClick, }: UseTagInteractionsArgs): TagInteractionHandlers => { const draggingTagRef = useRef(null); @@ -155,8 +153,6 @@ export const useTagInteractions = ({ return; } - requestCanvasFocus?.(); - // Double-check assignment (even though cursor logic tries to prevent it) const isAssigned = doc.tags?.some((t) => t.id === payload.id); if (isAssigned) return; @@ -166,7 +162,7 @@ export const useTagInteractions = ({ } }, 0); }, - [isTagTransfer, onAssignTagToDocument, requestCanvasFocus], + [isTagTransfer, onAssignTagToDocument], ); const onTagDragStart = useCallback( diff --git a/frontend/src/documents/panel/useDocumentsContextValues.ts b/frontend/src/documents/panel/useDocumentsContextValues.ts index b3aae5e..62e3f44 100644 --- a/frontend/src/documents/panel/useDocumentsContextValues.ts +++ b/frontend/src/documents/panel/useDocumentsContextValues.ts @@ -37,6 +37,9 @@ export const useDocumentsContextValues = (props: DocumentsPanelInnerProps) => { toggleCorrespondent: toggleCorrespondentFilter, } = useDocumentsFilter(); + const scrollRef = useRef(null); + const suppressDocumentClickRef = useRef(false); + // Handlers const tagHandlers = useTagInteractions({ onAssignTagToDocument: props.onDocumentTagAttach, @@ -73,10 +76,6 @@ export const useDocumentsContextValues = (props: DocumentsPanelInnerProps) => { selectedFolder, ]); - // Refs - const scrollRef = useRef(null); - const suppressDocumentClickRef = useRef(false); - const handleFolderClick = useCallback( (folder: any, event: any) => { if (!folder) {