Skip to content

Commit 31a108c

Browse files
fix(contracts): Space shortcuts reach clients instead of reverting to defaults (#34799)
1 parent 661a3e2 commit 31a108c

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎packages/contracts/src/keybindings.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ it.effect("drops resolved rules with commands this build does not know", () =>
3737
}),
3838
);
3939

40+
it.effect("round-trips resolved Space shortcuts", () =>
41+
Effect.gen(function* () {
42+
const codec = Schema.fromJsonString(ResolvedKeybindingsConfig);
43+
const rules = [
44+
{
45+
command: "composer.dictation" as const,
46+
shortcut: { ...shortcut, key: " ", metaKey: true, modKey: false },
47+
},
48+
];
49+
const encoded = yield* Schema.encodeEffect(codec)(rules);
50+
const parsed = yield* decode(codec, encoded);
51+
assert.deepEqual(parsed, rules);
52+
}),
53+
);
54+
4055
it.effect("drops malformed resolved rule entries", () =>
4156
Effect.gen(function* () {
4257
const parsed = yield* decode(ResolvedKeybindingsConfig, [

‎packages/contracts/src/keybindings.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,14 @@ export const KeybindingsConfig = Schema.Array(KeybindingRule).check(
154154
);
155155
export type KeybindingsConfig = typeof KeybindingsConfig.Type;
156156

157+
// Untrimmed: the `space` token resolves to the key " ".
158+
const KeybindingShortcutKey = Schema.String.check(
159+
Schema.isMinLength(1),
160+
Schema.isMaxLength(MAX_KEYBINDING_VALUE_LENGTH),
161+
);
162+
157163
export const KeybindingShortcut = Schema.Struct({
158-
key: KeybindingValue,
164+
key: KeybindingShortcutKey,
159165
metaKey: Schema.Boolean,
160166
ctrlKey: Schema.Boolean,
161167
shiftKey: Schema.Boolean,

0 commit comments

Comments
 (0)