Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/renderer/commands/defaultKeybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,43 @@ describe("default keybindings", () => {
inputFocus: true,
}),
).toBe(false);
expect(
evaluateWhenClause(bindings["pane.close"]?.when, {
...idleThreadContext,
panelFocus: true,
}),
).toBe(false);
expect(
evaluateWhenClause(bindings["pane.close"]?.when, {
...idleThreadContext,
browserFocus: true,
}),
).toBe(false);
expect(
evaluateWhenClause(bindings["pane.close"]?.when, {
...idleThreadContext,
composerFocus: true,
}),
).toBe(false);
expect(evaluateWhenClause(bindings["thread.search.open"]?.when, idleThreadContext)).toBe(true);
expect(
evaluateWhenClause(bindings["thread.search.open"]?.when, {
...idleThreadContext,
panelFocus: true,
}),
).toBe(false);
expect(
evaluateWhenClause(bindings["thread.search.open"]?.when, {
...idleThreadContext,
browserFocus: true,
}),
).toBe(false);
expect(
evaluateWhenClause(bindings["thread.search.open"]?.when, {
...idleThreadContext,
composerFocus: true,
}),
).toBe(false);
expect(evaluateWhenClause(bindings["editor.save"]?.when, { editorFocus: true })).toBe(true);
expect(evaluateWhenClause(bindings["editor.save"]?.when, { editorOpen: true })).toBe(false);
});
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/commands/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ export function buildWhenContext(
const inputFocus = isTextInputElement(element);
const editorFocus = Boolean(element?.closest(".monaco-editor"));
const terminalFocus = Boolean(element?.closest(".xterm"));
const composerFocus = Boolean(
element?.closest("[data-lightcode-composer], .lightcode-composer-shell"),
);
const panelFocus = Boolean(element?.closest("[data-lightcode-panel], [data-overlay-surface]"));
const browserFocus = Boolean(element?.closest("[data-lightcode-browser]"));

return {
paletteOpen,
inputFocus,
editorFocus,
composerFocus,
editorOpen: Boolean(fileEditor.activePath || fileEditor.rootContext),
terminalFocus,
terminalOpen: terminal.isOpen,
panelFocus,
browserFocus,
hasProject: Boolean(active.project),
hasThread: Boolean(active.thread),
view: app.view.kind,
Expand Down
53 changes: 53 additions & 0 deletions src/renderer/commands/shortcutCatalog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_KEYBINDINGS } from "@/shared/keybindings";
import { buildCommandRegistry } from "./registry";
import { buildShortcutRows, SHORTCUT_CONTEXTS, type ShortcutContext } from "./shortcutCatalog";
import { formatKeybinding, type PlatformName } from "./keybindingMatcher";

const PLATFORMS: PlatformName[] = ["darwin", "win32", "linux"];
const CONTEXTS = SHORTCUT_CONTEXTS.map((context) => context.id).filter(
(context): context is Exclude<ShortcutContext, "all"> => context !== "all",
);

describe("shortcut catalog", () => {
it("lists Shift+F5 for browser hard reload", () => {
for (const platform of PLATFORMS) {
const rows = buildShortcutRows(
buildCommandRegistry(),
DEFAULT_KEYBINDINGS.keybindings,
platform,
);
const row = rows.find((item) => item.id === "browser.hard-reload");

expect(row?.keys).toContain(formatKeybinding("Shift+F5", platform));
}
});

it("does not show conflicting shortcuts inside a context", () => {
const conflicts: string[] = [];

for (const platform of PLATFORMS) {
const rows = buildShortcutRows(
buildCommandRegistry(),
DEFAULT_KEYBINDINGS.keybindings,
platform,
);

for (const context of CONTEXTS) {
const seen = new Map<string, string>();
for (const row of rows) {
if (!row.contexts.includes(context)) continue;
for (const key of row.keys) {
const previous = seen.get(key);
if (previous) {
conflicts.push(`${platform} ${context} ${key}: ${previous} vs ${row.id}`);
}
seen.set(key, row.id);
}
}
}
}

expect(conflicts).toEqual([]);
});
});
Loading