mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
Prevent accidental tab drags when clicking (#6210)
This commit is contained in:
@@ -10,6 +10,8 @@ import type { TabDragItemData } from './useTabDragSplit'
|
||||
import {
|
||||
canDropTabForPaneColumnSplit,
|
||||
canDropTabIntoPaneBody,
|
||||
getTabDragActivationDistance,
|
||||
TAB_DRAG_ACTIVATION_DISTANCE_PX,
|
||||
useTabDragSplit
|
||||
} from './useTabDragSplit'
|
||||
|
||||
@@ -177,6 +179,21 @@ afterEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('tab drag activation distance', () => {
|
||||
it('uses the named threshold for enabled tab drags', () => {
|
||||
expect(TAB_DRAG_ACTIVATION_DISTANCE_PX).toBe(12)
|
||||
expect(getTabDragActivationDistance(true)).toBe(TAB_DRAG_ACTIVATION_DISTANCE_PX)
|
||||
})
|
||||
|
||||
it('keeps enabled tab drags above the old overly-sensitive distance', () => {
|
||||
expect(TAB_DRAG_ACTIVATION_DISTANCE_PX).toBeGreaterThan(5)
|
||||
})
|
||||
|
||||
it('uses an impossible activation distance when tab dragging is disabled', () => {
|
||||
expect(getTabDragActivationDistance(false)).toBe(Number.MAX_SAFE_INTEGER)
|
||||
})
|
||||
})
|
||||
|
||||
describe('canDropTabIntoPaneBody', () => {
|
||||
it('rejects pane-body drops that would split a single tab onto itself', () => {
|
||||
expect(
|
||||
|
||||
@@ -45,6 +45,10 @@ export type { HoveredTabInsertion }
|
||||
|
||||
export type TabDropZone = 'center' | TabSplitDirection
|
||||
|
||||
// Why: tab activation waits for pointerup, so dnd-kit needs enough movement
|
||||
// tolerance to avoid treating ordinary click jitter as an intentional drag.
|
||||
export const TAB_DRAG_ACTIVATION_DISTANCE_PX = 12
|
||||
|
||||
export type TabDragItemData = {
|
||||
kind: 'tab'
|
||||
worktreeId: string
|
||||
@@ -145,6 +149,10 @@ export function getTabPaneBodyDroppableId(groupId: string): UniqueIdentifier {
|
||||
return `tab-group-pane-body:${groupId}`
|
||||
}
|
||||
|
||||
export function getTabDragActivationDistance(enabled: boolean): number {
|
||||
return enabled ? TAB_DRAG_ACTIVATION_DISTANCE_PX : Number.MAX_SAFE_INTEGER
|
||||
}
|
||||
|
||||
export function useTabDragSplit({
|
||||
worktreeId,
|
||||
enabled = true
|
||||
@@ -187,7 +195,7 @@ export function useTabDragSplit({
|
||||
// the sensors array into a useEffect dependency list — changing its
|
||||
// length between renders violates React's rules of hooks.
|
||||
const pointerSensor = useSensor(PointerSensor, {
|
||||
activationConstraint: { distance: enabled ? 5 : Number.MAX_SAFE_INTEGER }
|
||||
activationConstraint: { distance: getTabDragActivationDistance(enabled) }
|
||||
})
|
||||
const sensors = useSensors(pointerSensor)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user