From dd2e8f258d03d3385f03015ce0f6dea555142b0d Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 22:10:25 -0400 Subject: [PATCH] Handle double-click submission in DocumentExplorer actions (#12417) * Initial plan * Support double-click submit in document explorer * Remove test * Fix double-click submit in document explorer Single click now sets the selection instead of toggling it, so the two clicks preceding a dblclick no longer flicker the selection on/off. Submit handlers accept the node directly to avoid the stale-state race across the click sequence, and button onClick handlers are wrapped so the synthetic MouseEvent isn't passed in as the path argument. Co-Authored-By: Claude Opus 4.7 * PR feedback --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Tom Moor Co-authored-by: Claude Opus 4.7 --- .../DocumentExplorer/DocumentCopy.tsx | 12 +++++------- .../DocumentExplorer/DocumentExplorer.tsx | 17 +++++++++++++---- .../DocumentExplorer/DocumentExplorerNode.tsx | 6 +++++- .../DocumentExplorerSearchResult.tsx | 3 +++ .../DocumentExplorer/DocumentMove.tsx | 10 +++++----- .../DocumentExplorer/TemplateMove.tsx | 9 ++++----- app/scenes/DocumentPublish.tsx | 10 +++++----- 7 files changed, 40 insertions(+), 27 deletions(-) diff --git a/app/components/DocumentExplorer/DocumentCopy.tsx b/app/components/DocumentExplorer/DocumentCopy.tsx index 0210a6a078..fe36f738e3 100644 --- a/app/components/DocumentExplorer/DocumentCopy.tsx +++ b/app/components/DocumentExplorer/DocumentCopy.tsx @@ -40,8 +40,8 @@ function DocumentCopy({ document, onSubmit }: Props) { return nodes; }, [policies, collectionTrees]); - const copy = async () => { - if (!selectedPath) { + const copy = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to copy")); return; } @@ -52,10 +52,8 @@ function DocumentCopy({ document, onSubmit }: Props) { publish, recursive, title: document.title, - collectionId: selectedPath.collectionId, - ...(selectedPath.type === "document" - ? { parentDocumentId: selectedPath.id } - : {}), + collectionId: path.collectionId, + ...(path.type === "document" ? { parentDocumentId: path.id } : {}), }); toast.success(t("Document copied")); @@ -111,7 +109,7 @@ function DocumentCopy({ document, onSubmit }: Props) { t("Select a location to copy") )} - diff --git a/app/components/DocumentExplorer/DocumentExplorer.tsx b/app/components/DocumentExplorer/DocumentExplorer.tsx index 7bb06360ed..daa6dccde1 100644 --- a/app/components/DocumentExplorer/DocumentExplorer.tsx +++ b/app/components/DocumentExplorer/DocumentExplorer.tsx @@ -31,7 +31,7 @@ import useStores from "~/hooks/useStores"; type Props = { /** Action taken upon submission of selected item, could be publish, move etc. */ - onSubmit: () => void; + onSubmit: (item: NavigationNode | null) => void; /** A side-effect of item selection */ onSelect: (item: NavigationNode | null) => void; /** Items to be shown in explorer */ @@ -255,6 +255,13 @@ function DocumentExplorer({ } }; + const submitNode = (node: number) => { + const selectedNode = nodes[node]; + + selectNode(selectedNode); + onSubmit(selectedNode); + }; + const ListItem = observer( ({ index, @@ -311,7 +318,8 @@ function DocumentExplorer({ width: `calc(${style.width} - ${HORIZONTAL_PADDING * 2}px)`, }} onPointerMove={() => setActiveNode(index)} - onClick={() => toggleSelect(index)} + onClick={() => selectNode(nodes[index])} + onDoubleClick={() => submitNode(index)} icon={renderedIcon} title={title} path={path} @@ -325,7 +333,8 @@ function DocumentExplorer({ width: `calc(${style.width} - ${HORIZONTAL_PADDING * 2}px)`, }} onPointerMove={() => setActiveNode(index)} - onClick={() => toggleSelect(index)} + onClick={() => selectNode(nodes[index])} + onDoubleClick={() => submitNode(index)} onDisclosureClick={(ev) => { ev.stopPropagation(); toggleCollapse(index); @@ -387,7 +396,7 @@ function DocumentExplorer({ } case "Enter": { if (isModKey(ev)) { - onSubmit(); + onSubmit(selectedNode); } else { toggleSelect(activeNode); } diff --git a/app/components/DocumentExplorer/DocumentExplorerNode.tsx b/app/components/DocumentExplorer/DocumentExplorerNode.tsx index b4556d0c97..a47984d48c 100644 --- a/app/components/DocumentExplorer/DocumentExplorerNode.tsx +++ b/app/components/DocumentExplorer/DocumentExplorerNode.tsx @@ -29,8 +29,10 @@ type Props = { onDisclosureClick: (ev: React.MouseEvent) => void; /** Fired on pointer movement over the node; used to update the active highlight. */ onPointerMove: (ev: React.MouseEvent) => void; - /** Fired when the node is clicked to toggle its selection. */ + /** Fired when the node is clicked to select it. */ onClick: (ev: React.MouseEvent) => void; + /** Fired when the node is double-clicked to submit the current selection. */ + onDoubleClick: (ev: React.MouseEvent) => void; }; function DocumentExplorerNode( @@ -46,6 +48,7 @@ function DocumentExplorerNode( onDisclosureClick, onPointerMove, onClick, + onDoubleClick, }: Props, ref: React.RefObject ) { @@ -59,6 +62,7 @@ function DocumentExplorerNode( selected={selected} active={active} onClick={onClick} + onDoubleClick={onDoubleClick} style={style} onPointerMove={onPointerMove} role="option" diff --git a/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx b/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx index 0b41ec9241..38d5449080 100644 --- a/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx +++ b/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx @@ -17,6 +17,7 @@ type Props = { onPointerMove: (ev: React.MouseEvent) => void; onClick: (ev: React.MouseEvent) => void; + onDoubleClick: (ev: React.MouseEvent) => void; }; function DocumentExplorerSearchResult({ @@ -28,6 +29,7 @@ function DocumentExplorerSearchResult({ path, onPointerMove, onClick, + onDoubleClick, }: Props) { const { t } = useTranslation(); @@ -36,6 +38,7 @@ function DocumentExplorerSearchResult({ selected={selected} active={active} onClick={onClick} + onDoubleClick={onDoubleClick} style={style} onPointerMove={onPointerMove} role="option" diff --git a/app/components/DocumentExplorer/DocumentMove.tsx b/app/components/DocumentExplorer/DocumentMove.tsx index 5a05f74474..80d9640a47 100644 --- a/app/components/DocumentExplorer/DocumentMove.tsx +++ b/app/components/DocumentExplorer/DocumentMove.tsx @@ -56,17 +56,17 @@ function DocumentMove({ document }: Props) { return nodes; }, [policies, collectionTrees, document.id]); - const move = async () => { - if (!selectedPath) { + const move = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to move")); return; } try { setMoving(true); - const { type, id: parentDocumentId } = selectedPath; + const { type, id: parentDocumentId } = path; - const collectionId = selectedPath.collectionId as string; + const collectionId = path.collectionId as string; if (type === "document") { await document.move({ collectionId, parentDocumentId }); @@ -103,7 +103,7 @@ function DocumentMove({ document }: Props) { t("Select a location to move") )} - diff --git a/app/components/DocumentExplorer/TemplateMove.tsx b/app/components/DocumentExplorer/TemplateMove.tsx index b472f38107..d16ca6941b 100644 --- a/app/components/DocumentExplorer/TemplateMove.tsx +++ b/app/components/DocumentExplorer/TemplateMove.tsx @@ -33,15 +33,14 @@ function TemplateMove({ template }: Props) { [policies, collectionTrees] ); - const move = async () => { - if (!selectedPath) { + const move = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to move")); return; } try { - const collectionId = (selectedPath.collectionId ?? - selectedPath.id) as string; + const collectionId = (path.collectionId ?? path.id) as string; await template.save({ collectionId }); toast.success(t("Template moved")); @@ -76,7 +75,7 @@ function TemplateMove({ template }: Props) { t("Select a location to move") )} - diff --git a/app/scenes/DocumentPublish.tsx b/app/scenes/DocumentPublish.tsx index 16005c94a4..a80fd18212 100644 --- a/app/scenes/DocumentPublish.tsx +++ b/app/scenes/DocumentPublish.tsx @@ -33,16 +33,16 @@ function DocumentPublish({ document }: Props) { [policies, collectionTrees] ); - const publish = async () => { - if (!selectedPath) { + const publish = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to publish")); return; } try { - const { type, id: parentDocumentId } = selectedPath; + const { type, id: parentDocumentId } = path; - const collectionId = selectedPath.collectionId as string; + const collectionId = path.collectionId as string; // Also move it under if selected path corresponds to another doc if (type === "document") { @@ -83,7 +83,7 @@ function DocumentPublish({ document }: Props) { t("Select a location to publish") )} -