Skip to content

Commit bf6ef90

Browse files
johan vazcodex
authored andcommitted
fix(contracts): Space shortcuts survive the resolved keybindings contract
The normalized Space key is a single space, but KeybindingShortcut.key used the trimmed rule-text schema, so a resolved `mod+space` rule decoded to an empty key and clients silently dropped it. Validate the resolved key as a non-empty, bounded, untrimmed string; textual rule keys keep trimming. Co-Authored-By: GPT-6.1 Sol (Codex) <[email protected]>
1 parent 567a105 commit bf6ef90

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const decode = <S extends Schema.Top>(
1414
never
1515
>;
1616

17+
const encodeResolvedKeybindings = Schema.encodeEffect(ResolvedKeybindingsConfig);
18+
1719
const shortcut = {
1820
key: "p",
1921
metaKey: false,
@@ -39,14 +41,16 @@ it.effect("drops resolved rules with commands this build does not know", () =>
3941

4042
it.effect("drops malformed resolved rule entries", () =>
4143
Effect.gen(function* () {
44+
const spaceRule = { command: "terminal.split" as const, shortcut: { ...shortcut, key: " " } };
45+
const validRules = [{ command: "terminal.toggle" as const, shortcut }, spaceRule];
4246
const parsed = yield* decode(ResolvedKeybindingsConfig, [
4347
"garbage",
44-
{ command: "terminal.toggle", shortcut },
48+
...validRules,
49+
{ command: "terminal.toggle", shortcut: { ...shortcut, key: "" } },
50+
{ command: "terminal.toggle", shortcut: { ...shortcut, key: "x".repeat(65) } },
4551
null,
4652
]);
47-
assert.deepEqual(
48-
parsed.map((rule) => rule.command),
49-
["terminal.toggle"],
50-
);
53+
assert.deepEqual(parsed, validRules);
54+
assert.deepEqual(yield* encodeResolvedKeybindings(parsed), validRules);
5155
}),
5256
);

‎packages/contracts/src/keybindings.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const KeybindingsConfig = Schema.Array(KeybindingRule).check(
152152
export type KeybindingsConfig = typeof KeybindingsConfig.Type;
153153

154154
export const KeybindingShortcut = Schema.Struct({
155-
key: KeybindingValue,
155+
key: Schema.NonEmptyString.check(Schema.isMaxLength(MAX_KEYBINDING_VALUE_LENGTH)),
156156
metaKey: Schema.Boolean,
157157
ctrlKey: Schema.Boolean,
158158
shiftKey: Schema.Boolean,

0 commit comments

Comments
 (0)