Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(layers): stop space from activating row drag

joshistoast3dd9d52ca25c
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx
index 16fe6408e0..178860ce1d 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerGroupSection.tsx
@@ -6,9 +6,9 @@ import type { LucideIcon } from 'lucide-react';
import type { Dispatch } from 'react';
import { Collapsible, HStack, Icon, Stack, Text } from '@chakra-ui/react';
-import { closestCenter, DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
+import { closestCenter, DndContext, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
import { restrictToParentElement, restrictToVerticalAxis } from '@dnd-kit/modifiers';
-import { SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy } from '@dnd-kit/sortable';
+import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
import { canMergeVisibleRasters } from '@workbench/canvas-engine/document/mergeVisible';
import { IconButton, toaster, Tooltip } from '@workbench/components/ui';
import { useActiveProjectName } from '@workbench/WorkbenchContext';
@@ -27,7 +27,6 @@ import { useAddLayer } from './useAddLayer';
const DND_MODIFIERS = [restrictToVerticalAxis, restrictToParentElement];
const POINTER_SENSOR_OPTIONS = { activationConstraint: { distance: 6 } } as const;
-const KEYBOARD_SENSOR_OPTIONS = { coordinateGetter: sortableKeyboardCoordinates } as const;
interface LayerGroupSectionProps {
dispatch: Dispatch<WorkbenchAction>;
@@ -60,10 +59,7 @@ export const LayerGroupSection = ({
}: LayerGroupSectionProps) => {
const { t } = useTranslation();
- const sensors = useSensors(
- useSensor(PointerSensor, POINTER_SENSOR_OPTIONS),
- useSensor(KeyboardSensor, KEYBOARD_SENSOR_OPTIONS)
- );
+ const sensors = useSensors(useSensor(PointerSensor, POINTER_SENSOR_OPTIONS));
const globalIndexById = useMemo(() => {
const map = new Map<string, number>();
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx
index 045b9d4fa0..37f0a6fbd4 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerListItem.tsx
@@ -44,7 +44,7 @@ interface LayerListItemProps {
*/
export const LayerListItem = ({ dispatch, engine, index, isSelected, layer, layers }: LayerListItemProps) => {
const { t } = useTranslation();
- const { attributes, isDragging, listeners, setNodeRef, transform, transition } = useSortable({ id: layer.id });
+ const { isDragging, listeners, setNodeRef, transform, transition } = useSortable({ id: layer.id });
const [isEditing, setIsEditing] = useState(false);
const [draftName, setDraftName] = useState(layer.name);
const [contextMenuTarget, setContextMenuTarget] = useState<CanvasLayerContextMenuTarget | null>(null);
@@ -109,11 +109,7 @@ export const LayerListItem = ({ dispatch, engine, index, isSelected, layer, laye
const handleNameKeyDown = useCallback(
(event: KeyboardEvent<HTMLInputElement>) => {
- // Keep every keystroke inside the rename input. The whole row carries
- // dnd-kit keyboard `listeners` whose activator claims Space/Enter (and
- // preventDefaults them) to arm a keyboard drag — without this guard, typing
- // a space in a layer name is eaten and can start a drag. Stop propagation
- // for ALL keys (not just the two we handle) so nothing bubbles to the row.
+ // Keep rename keystrokes from reaching canvas-level shortcuts.
event.stopPropagation();
if (event.key === 'Enter') {
commitName();
@@ -141,7 +137,6 @@ export const LayerListItem = ({ dispatch, engine, index, isSelected, layer, laye
return (
<Box ref={setNodeRef} style={dndStyle}>
<Row
- {...attributes}
{...listeners}
active={isSelected ? 'muted' : undefined}
cursor={isDragging ? 'grabbing' : 'default'}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerDndWiring.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerDndWiring.test.ts
new file mode 100644
index 0000000000..8f175801a7
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerDndWiring.test.ts
@@ -0,0 +1,20 @@
+import { describe, expect, it } from 'vitest';
+
+import * as layerGroupSectionModule from './LayerGroupSection.tsx?raw';
+import * as layerListItemModule from './LayerListItem.tsx?raw';
+
+const layerGroupSectionSource = layerGroupSectionModule.default;
+const layerListItemSource = layerListItemModule.default;
+
+describe('layer drag-and-drop wiring', () => {
+ it('registers pointer dragging without a keyboard sensor', () => {
+ expect(layerGroupSectionSource).toContain('useSensor(PointerSensor, POINTER_SENSOR_OPTIONS)');
+ expect(layerGroupSectionSource).not.toContain('KeyboardSensor');
+ expect(layerGroupSectionSource).not.toContain('sortableKeyboardCoordinates');
+ });
+
+ it('keeps pointer listeners on the row without keyboard-interactive sortable attributes', () => {
+ expect(layerListItemSource).toContain('{...listeners}');
+ expect(layerListItemSource).not.toContain('{...attributes}');
+ });
+});