GeezerVison is showing github.com — fix(contracts): Space shortcuts reach clients instead of reverting to… · pingdotgg/t3code@31a108c
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/contracts/src/keybindings.test.ts +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,21 @@ it.effect("drops resolved rules with commands this build does not know", () => |
37 | 37 | }), |
38 | 38 | ); |
39 | 39 |
|
| 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 | + |
40 | 55 | it.effect("drops malformed resolved rule entries", () => |
41 | 56 | Effect.gen(function* () { |
42 | 57 | const parsed = yield* decode(ResolvedKeybindingsConfig, [ |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/contracts/src/keybindings.ts +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -154,8 +154,14 @@ export const KeybindingsConfig = Schema.Array(KeybindingRule).check( |
154 | 154 | ); |
155 | 155 | export type KeybindingsConfig = typeof KeybindingsConfig.Type; |
156 | 156 |
|
| 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 | + |
157 | 163 | export const KeybindingShortcut = Schema.Struct({ |
158 | | - key: KeybindingValue, |
| 164 | + key: KeybindingShortcutKey, |
159 | 165 | metaKey: Schema.Boolean, |
160 | 166 | ctrlKey: Schema.Boolean, |
161 | 167 | shiftKey: Schema.Boolean, |
|