Skip to content

Commit 1e82c17

Browse files
committed
fix(contracts): keep Space shortcuts after saving keybindings
1 parent 6577c6b commit 1e82c17

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as Effect from "effect/Effect";
44

55
import { ResolvedKeybindingsConfig } from "./keybindings.ts";
66

7+
const encodeResolvedKeybindings = Schema.encodeEffect(ResolvedKeybindingsConfig);
8+
79
const decode = <S extends Schema.Top>(
810
schema: S,
911
input: unknown,
@@ -23,6 +25,20 @@ const shortcut = {
2325
modKey: true,
2426
};
2527

28+
it.effect("preserves Space shortcuts through resolved keybinding serialization", () =>
29+
Effect.gen(function* () {
30+
const rules = [
31+
{
32+
command: "composer.dictation" as const,
33+
shortcut: { ...shortcut, key: " ", metaKey: true, modKey: false },
34+
},
35+
];
36+
const encoded = yield* encodeResolvedKeybindings(rules);
37+
assert.deepEqual(encoded, rules);
38+
assert.deepEqual(yield* decode(ResolvedKeybindingsConfig, encoded), rules);
39+
}),
40+
);
41+
2642
it.effect("drops resolved rules with commands this build does not know", () =>
2743
Effect.gen(function* () {
2844
const parsed = yield* decode(ResolvedKeybindingsConfig, [

‎packages/contracts/src/keybindings.ts‎

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

155155
export const KeybindingShortcut = Schema.Struct({
156-
key: KeybindingValue,
156+
// Resolved Space is a literal " "; trimming it loses the shortcut on the wire.
157+
key: Schema.NonEmptyString.check(Schema.isMaxLength(MAX_KEYBINDING_VALUE_LENGTH)),
157158
metaKey: Schema.Boolean,
158159
ctrlKey: Schema.Boolean,
159160
shiftKey: Schema.Boolean,

0 commit comments

Comments
 (0)