Skip to content
Merged
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
15 changes: 15 additions & 0 deletions packages/contracts/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ it.effect("drops resolved rules with commands this build does not know", () =>
}),
);

it.effect("round-trips resolved Space shortcuts", () =>
Effect.gen(function* () {
const codec = Schema.fromJsonString(ResolvedKeybindingsConfig);
const rules = [
{
command: "composer.dictation" as const,
shortcut: { ...shortcut, key: " ", metaKey: true, modKey: false },
},
];
const encoded = yield* Schema.encodeEffect(codec)(rules);
const parsed = yield* decode(codec, encoded);
assert.deepEqual(parsed, rules);
}),
);

it.effect("drops malformed resolved rule entries", () =>
Effect.gen(function* () {
const parsed = yield* decode(ResolvedKeybindingsConfig, [
Expand Down
8 changes: 7 additions & 1 deletion packages/contracts/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ export const KeybindingsConfig = Schema.Array(KeybindingRule).check(
);
export type KeybindingsConfig = typeof KeybindingsConfig.Type;

// Untrimmed: the `space` token resolves to the key " ".
const KeybindingShortcutKey = Schema.String.check(
Schema.isMinLength(1),
Schema.isMaxLength(MAX_KEYBINDING_VALUE_LENGTH),
);

export const KeybindingShortcut = Schema.Struct({
key: KeybindingValue,
key: KeybindingShortcutKey,
metaKey: Schema.Boolean,
ctrlKey: Schema.Boolean,
shiftKey: Schema.Boolean,
Expand Down
Loading