feat: add command palette functionality and shortcuts
- Implemented command palette with keyboard shortcut (⌘K) for opening. - Added commands for opening, closing, setting query, and selecting items in the command palette. - Created tests for command palette commands and input handling. - Enhanced layer actions with functions for adding, grouping, and deleting layers. - Updated UI components to integrate command palette and shortcuts.
This commit is contained in:
28
input/command-palette.test.ts
Normal file
28
input/command-palette.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { commandIds } from "@commands/ids";
|
||||
import { handleCommandPaletteKey } from "./command-palette";
|
||||
|
||||
describe("command palette input", () => {
|
||||
test("opens the command palette with the platform shortcut", () => {
|
||||
const dispatched: unknown[] = [];
|
||||
const consumed = handleCommandPaletteKey({
|
||||
event: { key: "k", code: "KeyK", altKey: false, ctrlKey: false, metaKey: true, shiftKey: false },
|
||||
dispatch: (commandId, payload) => {
|
||||
dispatched.push({ commandId, payload });
|
||||
return undefined as never;
|
||||
},
|
||||
});
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(dispatched).toEqual([{ commandId: commandIds.commandPaletteOpen, payload: undefined }]);
|
||||
});
|
||||
|
||||
test("ignores unmodified K so the chroma key tool keeps its shortcut", () => {
|
||||
const consumed = handleCommandPaletteKey({
|
||||
event: { key: "k", code: "KeyK", altKey: false, ctrlKey: false, metaKey: false, shiftKey: false },
|
||||
dispatch: () => undefined as never,
|
||||
});
|
||||
|
||||
expect(consumed).toBe(false);
|
||||
});
|
||||
});
|
||||
12
input/command-palette.ts
Normal file
12
input/command-palette.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { commandIds } from "@commands/ids";
|
||||
import type { Dispatch } from "@commands/dispatcher";
|
||||
import type { KeybindEvent } from "./keyboard";
|
||||
|
||||
export function handleCommandPaletteKey(options: { event: KeybindEvent; dispatch: Dispatch }): boolean {
|
||||
if (options.event.altKey || options.event.shiftKey) return false;
|
||||
const modifier = options.event.metaKey || options.event.ctrlKey;
|
||||
if (!modifier || options.event.key.toLowerCase() !== "k") return false;
|
||||
|
||||
options.dispatch(commandIds.commandPaletteOpen, undefined);
|
||||
return true;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ export {
|
||||
} from "./dom";
|
||||
export type { CommandKeybind, GlobalKeybindConsumer, Keybind, KeybindEvent, KeybindMap } from "./keyboard";
|
||||
export { handleKeybind, keybindFromEvent } from "./keyboard";
|
||||
export { handleCommandPaletteKey } from "./command-palette";
|
||||
export { handleHistoryKey } from "./history";
|
||||
export { handleToolKey } from "./tool-keybinds";
|
||||
export { findGroup, findLayerInfoInDocument, handleDeleteSelectionKey, resolveLayerDrop } from "./layers-panel";
|
||||
|
||||
Reference in New Issue
Block a user