Skip to content

Commit 1821af5

Browse files
committed
fix(chats): preserve selection for modified and overlay clicks
1 parent 79a9221 commit 1821af5

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎apps/sim/app/o/[organizationId]/components/organization-sidebar/organization-sidebar.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
SIDEBAR_SECTION_GAP_CLASS,
3838
} from '@/app/workspace/[workspaceId]/w/components/sidebar/constants'
3939
import { useSidebarResize } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
40+
import { isSidebarBackgroundClick } from '@/app/workspace/[workspaceId]/w/components/sidebar/utils'
4041
import { useContextMenu } from '@/hooks/use-context-menu'
4142
import { useFolderStore } from '@/stores/folders/store'
4243
import { useSidebarStore } from '@/stores/sidebar/store'
@@ -146,9 +147,7 @@ export const OrganizationSidebar = memo(function OrganizationSidebar() {
146147
}
147148

148149
const handleSidebarClick = (event: React.MouseEvent<HTMLElement>) => {
149-
if (event.target instanceof Element && event.target.closest('button, [role="button"], a')) {
150-
return
151-
}
150+
if (!isSidebarBackgroundClick(event)) return
152151
useFolderStore.getState().clearChatSelection()
153152
}
154153

‎apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/chat-navigation-link/chat-navigation-link.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ function IntentAwareChatNavigationLink({
138138
onTouchStart={onTouchStart}
139139
onClick={(event) => {
140140
onClick?.(event)
141-
if (!event.defaultPrevented && !event.metaKey && !event.ctrlKey && onSelectChat) {
141+
if (
142+
!event.defaultPrevented &&
143+
!event.metaKey &&
144+
!event.ctrlKey &&
145+
!event.altKey &&
146+
onSelectChat
147+
) {
142148
if (event.shiftKey) event.preventDefault()
143149
onSelectChat(chatId, event.shiftKey)
144150
}

‎apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import {
115115
compareByOrder,
116116
createSidebarDragGhost,
117117
groupWorkflowsByFolder,
118+
isSidebarBackgroundClick,
118119
} from '@/app/workspace/[workspaceId]/w/components/sidebar/utils'
119120
import { useImportWorkflow } from '@/app/workspace/[workspaceId]/w/hooks'
120121
import { useCustomBlockOverlayVersion } from '@/blocks/custom/client-overlay'
@@ -1101,10 +1102,7 @@ export const Sidebar = memo(function Sidebar({ organizationHref }: SidebarProps)
11011102
)
11021103

11031104
const handleSidebarClick = (e: React.MouseEvent<HTMLElement>) => {
1104-
const target = e.target as HTMLElement
1105-
if (target.tagName === 'BUTTON' || target.closest('button, [role="button"], a')) {
1106-
return
1107-
}
1105+
if (!isSidebarBackgroundClick(e)) return
11081106
const { selectOnly, clearAllSelection } = useFolderStore.getState()
11091107
workflowId ? selectOnly(workflowId) : clearAllSelection()
11101108
}

‎apps/sim/app/workspace/[workspaceId]/w/components/sidebar/utils.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
import type { MouseEvent } from 'react'
12
import type { MothershipResource } from '@/lib/mothership/resource-types'
23
import { getFolderMap } from '@/hooks/queries/utils/folder-cache'
34
import { getWorkflows } from '@/hooks/queries/utils/workflow-cache'
45
import type { FolderTreeNode } from '@/stores/folders/types'
56
import type { WorkflowMetadata } from '@/stores/workflows/registry/types'
67

8+
/** Distinguishes sidebar background clicks from controls and portaled overlays. */
9+
export function isSidebarBackgroundClick(event: MouseEvent<HTMLElement>): boolean {
10+
return (
11+
event.target instanceof Element &&
12+
event.currentTarget.contains(event.target) &&
13+
!event.target.closest('button, [role="button"], a')
14+
)
15+
}
16+
717
/**
818
* Builds a `MothershipResource` array from a sidebar drag selection so it can
919
* be set as `application/x-sim-resources` drag data and dropped into the chat.

0 commit comments

Comments
 (0)