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.

test(canvas): prove keyboard-root ownership and same-tool switches during a hold

Josh Corbettc787a45f2f16
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/input/pointerPipeline.browser.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/input/pointerPipeline.browser.test.ts
index bea636da37..dcc42bf780 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/input/pointerPipeline.browser.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/input/pointerPipeline.browser.test.ts
@@ -33,11 +33,17 @@ const createInputHarness = () => {
document.body.append(surface, button);
const events: string[] = [];
+ const deactivations: string[] = [];
const tools = Object.fromEntries(
(['brush', 'view', 'transform', 'bbox', 'eraser'] as const).map((id): [ToolId, Tool] => [
id,
{
id,
+ onDeactivate: (_ctx, options) => {
+ if (!options?.temporary) {
+ deactivations.push(id);
+ }
+ },
onKeyCommand: (_ctx, command) => events.push(`${id}:${command}`),
onPointerCancel: () => events.push(`${id}:cancel`),
onPointerDown: () => events.push(`${id}:down`),
@@ -92,7 +98,18 @@ const createInputHarness = () => {
});
const pointer = (type: string, buttons: number): PointerEvent =>
new PointerEvent(type, { bubbles: true, button: 0, buttons, pointerId: 1 });
- return { button, canvas, clicks: () => clicks, events, interaction, observed, pipeline, pointer, surface };
+ return {
+ button,
+ canvas,
+ clicks: () => clicks,
+ deactivations,
+ events,
+ interaction,
+ observed,
+ pipeline,
+ pointer,
+ surface,
+ };
};
describe('pointer pipeline in Chromium: keyboard ownership', () => {
@@ -189,6 +206,19 @@ describe('pointer pipeline in Chromium: keyboard ownership', () => {
});
describe('pointer pipeline in Chromium: tool switches during a hold', () => {
+ it('choosing the held tool again only ends the hold', async () => {
+ const h = createInputHarness();
+ h.pipeline.onPointerEnter();
+ h.surface.focus();
+
+ await userEvent.keyboard('{Space>}');
+ h.interaction.setTool('brush');
+ expect(h.interaction.getActiveToolId()).toBe('brush');
+ expect(h.deactivations).toEqual([]);
+ await userEvent.keyboard('{/Space}');
+ expect(h.interaction.getActiveToolId()).toBe('brush');
+ });
+
it('keeps a tool chosen while Space is still held when Space is released', async () => {
const h = createInputHarness();
h.interaction.setTool('eraser');
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.browser.test.tsx
index d9c68681c2..9a95cf35cb 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasSurface.browser.test.tsx
@@ -300,7 +300,7 @@ describe('CanvasSurface during a resize drag', () => {
});
describe('CanvasSurface keyboard ownership', () => {
- it('owns hold keys once the canvas is clicked, and leaves them to a tree row reached by keyboard', async () => {
+ it('gives hold keys to its keyboard root and leaves them to a tree row reached by keyboard', async () => {
const registry = createTrackedRegistry(20);
const { engine } = acquireTrackedEngine(registry, 'project-a', createEngineDeps(createEmptyCanvasState(64, 64)));
const host = document.createElement('div');
@@ -320,22 +320,27 @@ describe('CanvasSurface keyboard ownership', () => {
await nextFrame();
});
const overlay = host.querySelectorAll('canvas')[1]!;
+ const surface = overlay.parentElement!;
const row = host.querySelector<HTMLElement>('[role="treeitem"]')!;
const tool = () => engine.interaction.get('activeTool');
- const initial = tool();
+ engine.tools.setTool('brush');
- await userEvent.click(overlay);
- expect(document.activeElement).toBe(overlay.parentElement);
+ // Focus that did not arrive by pointer is owned only through the keyboard root.
+ await userEvent.hover(overlay);
+ await userEvent.keyboard('{Tab}');
+ surface.focus();
await userEvent.keyboard('{Space>}');
expect(tool()).toBe('view');
await userEvent.keyboard('{/Space}');
- expect(tool()).toBe(initial);
+ expect(tool()).toBe('brush');
+ await userEvent.click(overlay);
+ expect(document.activeElement).toBe(surface);
await userEvent.tab();
expect(document.activeElement).toBe(row);
await userEvent.hover(overlay);
await userEvent.keyboard('{Space>}');
- expect(tool()).toBe(initial);
+ expect(tool()).toBe('brush');
await userEvent.keyboard('{/Space}');
});
});