@inflatable-cookie/longhorn 0.4.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +77 -105
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
package/src/commands/keyboard.ts
CHANGED
|
@@ -12,10 +12,7 @@ import type {
|
|
|
12
12
|
CommandPlatform,
|
|
13
13
|
} from "./generated/protocol.ts";
|
|
14
14
|
import { shortcutLabel } from "./projectors.ts";
|
|
15
|
-
import type {
|
|
16
|
-
CommandExecutionOutcome,
|
|
17
|
-
CommandExecutionSource,
|
|
18
|
-
} from "./ports.ts";
|
|
15
|
+
import type { CommandExecutionOutcome, CommandExecutionSource } from "./ports.ts";
|
|
19
16
|
|
|
20
17
|
export interface KeyboardEventLike {
|
|
21
18
|
readonly code: string;
|
|
@@ -33,11 +30,11 @@ export interface KeyboardEventLike {
|
|
|
33
30
|
export interface CommandKeyboardResolutionOptions {
|
|
34
31
|
readonly platform: CommandPlatform;
|
|
35
32
|
readonly input: CommandKeyboardInput;
|
|
36
|
-
readonly contextPath:
|
|
33
|
+
readonly contextPath: ReadonlyArray<string>;
|
|
37
34
|
readonly mode: CommandKeyboardMode;
|
|
38
|
-
readonly bindings:
|
|
39
|
-
readonly commands:
|
|
40
|
-
readonly reserved?: (platform: CommandPlatform, chord: CommandKeyChord) => boolean;
|
|
35
|
+
readonly bindings: ReadonlyArray<CommandEffectiveBinding>;
|
|
36
|
+
readonly commands: ReadonlyArray<CommandDiscoveryRecord>;
|
|
37
|
+
readonly reserved?: ((platform: CommandPlatform, chord: CommandKeyChord) => boolean) | undefined;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
export interface CommandKeyboardDispatch {
|
|
@@ -47,8 +44,7 @@ export interface CommandKeyboardDispatch {
|
|
|
47
44
|
): Promise<CommandExecutionOutcome>;
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
export interface RouteKeyboardEventOptions
|
|
51
|
-
extends Omit<CommandKeyboardResolutionOptions, "input"> {
|
|
47
|
+
export interface RouteKeyboardEventOptions extends Omit<CommandKeyboardResolutionOptions, "input"> {
|
|
52
48
|
readonly dispatcher: CommandKeyboardDispatch;
|
|
53
49
|
readonly editableTarget?: (target: unknown) => boolean;
|
|
54
50
|
readonly onCapture?: (chord: CommandKeyChord, label: string) => void;
|
|
@@ -84,9 +80,15 @@ export function resolveCommandKeyboard(
|
|
|
84
80
|
options: CommandKeyboardResolutionOptions,
|
|
85
81
|
): CommandKeyResolution {
|
|
86
82
|
const { input } = options;
|
|
87
|
-
if (!validPhysicalCode(input.chord.code))
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
if (!validPhysicalCode(input.chord.code)) {
|
|
84
|
+
return { kind: "unbound" };
|
|
85
|
+
}
|
|
86
|
+
if (input.repeat) {
|
|
87
|
+
return gated("repeat");
|
|
88
|
+
}
|
|
89
|
+
if (input.composing) {
|
|
90
|
+
return gated("composition");
|
|
91
|
+
}
|
|
90
92
|
if (options.reserved?.(options.platform, input.chord) === true) {
|
|
91
93
|
return gated("reserved");
|
|
92
94
|
}
|
|
@@ -98,9 +100,7 @@ export function resolveCommandKeyboard(
|
|
|
98
100
|
};
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
const positions = new Map(
|
|
102
|
-
options.contextPath.map((contextId, index) => [contextId, index]),
|
|
103
|
-
);
|
|
103
|
+
const positions = new Map(options.contextPath.map((contextId, index) => [contextId, index]));
|
|
104
104
|
const matches = options.bindings
|
|
105
105
|
.flatMap((binding) => {
|
|
106
106
|
const specificity = positions.get(binding.contextId);
|
|
@@ -115,38 +115,34 @@ export function resolveCommandKeyboard(
|
|
|
115
115
|
})
|
|
116
116
|
.sort(
|
|
117
117
|
(left, right) =>
|
|
118
|
-
right.specificity - left.specificity ||
|
|
119
|
-
left.binding.id.localeCompare(right.binding.id),
|
|
118
|
+
right.specificity - left.specificity || left.binding.id.localeCompare(right.binding.id),
|
|
120
119
|
);
|
|
121
|
-
|
|
120
|
+
const [firstMatch] = matches;
|
|
121
|
+
if (firstMatch === undefined) {
|
|
122
|
+
return { kind: "unbound" };
|
|
123
|
+
}
|
|
122
124
|
|
|
123
|
-
const winningSpecificity =
|
|
124
|
-
const winningContext =
|
|
125
|
-
const winning = matches.filter(
|
|
126
|
-
|
|
127
|
-
);
|
|
128
|
-
const distinctInvocations = uniqueInvocations(
|
|
129
|
-
winning.map(({ binding }) => binding.invocation),
|
|
130
|
-
);
|
|
125
|
+
const winningSpecificity = firstMatch.specificity;
|
|
126
|
+
const winningContext = firstMatch.binding.contextId;
|
|
127
|
+
const winning = matches.filter(({ specificity }) => specificity === winningSpecificity);
|
|
128
|
+
const distinctInvocations = uniqueInvocations(winning.map(({ binding }) => binding.invocation));
|
|
131
129
|
const conflict = distinctInvocations.length > 1;
|
|
132
|
-
const representativeId =
|
|
133
|
-
const candidates: CommandBindingCandidate
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
: conflict
|
|
144
|
-
|
|
145
|
-
:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}),
|
|
149
|
-
);
|
|
130
|
+
const representativeId = firstMatch.binding.id;
|
|
131
|
+
const candidates: Array<CommandBindingCandidate> = matches.map(({ binding, specificity }) => ({
|
|
132
|
+
bindingId: binding.id,
|
|
133
|
+
source: binding.source,
|
|
134
|
+
matchedContextId: binding.contextId,
|
|
135
|
+
specificity,
|
|
136
|
+
invocation: binding.invocation,
|
|
137
|
+
disposition:
|
|
138
|
+
specificity < winningSpecificity
|
|
139
|
+
? { kind: "shadowed", byContextId: winningContext }
|
|
140
|
+
: conflict
|
|
141
|
+
? { kind: "conflict" }
|
|
142
|
+
: binding.id === representativeId
|
|
143
|
+
? { kind: "winner" }
|
|
144
|
+
: { kind: "equivalent" },
|
|
145
|
+
}));
|
|
150
146
|
|
|
151
147
|
if (conflict) {
|
|
152
148
|
const record: CommandKeymapConflict = {
|
|
@@ -159,10 +155,8 @@ export function resolveCommandKeyboard(
|
|
|
159
155
|
return { kind: "conflict", conflict: record, candidates };
|
|
160
156
|
}
|
|
161
157
|
|
|
162
|
-
const binding =
|
|
163
|
-
const declaration = options.commands.find(
|
|
164
|
-
({ id }) => id === binding.invocation.commandId,
|
|
165
|
-
);
|
|
158
|
+
const binding = firstMatch.binding;
|
|
159
|
+
const declaration = options.commands.find(({ id }) => id === binding.invocation.commandId);
|
|
166
160
|
if (input.editableText && declaration?.textInputPolicy === "blocked") {
|
|
167
161
|
return { kind: "gated", gate: "textInput", candidates };
|
|
168
162
|
}
|
|
@@ -185,8 +179,7 @@ export function routeCommandKeyboardEvent(
|
|
|
185
179
|
...options,
|
|
186
180
|
input: normalizeKeyboardEvent(event, options.editableTarget),
|
|
187
181
|
});
|
|
188
|
-
const consumed =
|
|
189
|
-
resolution.kind === "captured" || resolution.kind === "resolved";
|
|
182
|
+
const consumed = resolution.kind === "captured" || resolution.kind === "resolved";
|
|
190
183
|
if (consumed) {
|
|
191
184
|
event.preventDefault();
|
|
192
185
|
event.stopPropagation();
|
|
@@ -199,27 +192,29 @@ export function routeCommandKeyboardEvent(
|
|
|
199
192
|
return {
|
|
200
193
|
consumed,
|
|
201
194
|
resolution,
|
|
202
|
-
execution: options.dispatcher.dispatchInvocation(
|
|
203
|
-
resolution.winner.invocation,
|
|
204
|
-
"keyboard",
|
|
205
|
-
),
|
|
195
|
+
execution: options.dispatcher.dispatchInvocation(resolution.winner.invocation, "keyboard"),
|
|
206
196
|
};
|
|
207
197
|
}
|
|
208
198
|
return { consumed, resolution };
|
|
209
199
|
}
|
|
210
200
|
|
|
211
201
|
export function isEditableCommandTarget(target: unknown): boolean {
|
|
212
|
-
if (typeof target !== "object" || target === null)
|
|
202
|
+
if (typeof target !== "object" || target === null) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
213
205
|
const record = target as {
|
|
214
206
|
readonly isContentEditable?: boolean;
|
|
215
207
|
readonly tagName?: unknown;
|
|
216
208
|
readonly role?: unknown;
|
|
217
209
|
getAttribute?(name: string): string | null;
|
|
218
210
|
};
|
|
219
|
-
if (record.isContentEditable === true)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
211
|
+
if (record.isContentEditable === true) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
const tag = typeof record.tagName === "string" ? record.tagName.toLowerCase() : "";
|
|
215
|
+
if (tag === "input" || tag === "textarea" || tag === "select") {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
223
218
|
const role =
|
|
224
219
|
typeof record.getAttribute === "function"
|
|
225
220
|
? record.getAttribute("role")
|
|
@@ -229,9 +224,7 @@ export function isEditableCommandTarget(target: unknown): boolean {
|
|
|
229
224
|
return role === "textbox" || role === "searchbox";
|
|
230
225
|
}
|
|
231
226
|
|
|
232
|
-
function gated(
|
|
233
|
-
gate: "repeat" | "composition" | "reserved",
|
|
234
|
-
): CommandKeyResolution {
|
|
227
|
+
function gated(gate: "repeat" | "composition" | "reserved"): CommandKeyResolution {
|
|
235
228
|
return { kind: "gated", gate, candidates: [] };
|
|
236
229
|
}
|
|
237
230
|
|
|
@@ -251,8 +244,7 @@ function resolveBindingChord(
|
|
|
251
244
|
modifiers: {
|
|
252
245
|
control:
|
|
253
246
|
binding.trigger.modifiers.control ||
|
|
254
|
-
(binding.trigger.modifiers.primary &&
|
|
255
|
-
(platform === "windows" || platform === "linux")),
|
|
247
|
+
(binding.trigger.modifiers.primary && (platform === "windows" || platform === "linux")),
|
|
256
248
|
alt: binding.trigger.modifiers.alt,
|
|
257
249
|
shift: binding.trigger.modifiers.shift,
|
|
258
250
|
meta:
|
|
@@ -273,8 +265,8 @@ function sameChord(left: CommandKeyChord, right: CommandKeyChord): boolean {
|
|
|
273
265
|
}
|
|
274
266
|
|
|
275
267
|
function uniqueInvocations(
|
|
276
|
-
invocations:
|
|
277
|
-
): CommandInvocation
|
|
268
|
+
invocations: ReadonlyArray<CommandInvocation>,
|
|
269
|
+
): Array<CommandInvocation> {
|
|
278
270
|
const keyed = new Map<string, CommandInvocation>();
|
|
279
271
|
for (const invocation of invocations) {
|
|
280
272
|
keyed.set(invocationKey(invocation), invocation);
|
|
@@ -289,26 +281,30 @@ function invocationKey(invocation: CommandInvocation): string {
|
|
|
289
281
|
return JSON.stringify([invocation.commandId, argumentsKey]);
|
|
290
282
|
}
|
|
291
283
|
|
|
292
|
-
function compareInvocation(
|
|
293
|
-
left: CommandInvocation,
|
|
294
|
-
right: CommandInvocation,
|
|
295
|
-
): number {
|
|
284
|
+
function compareInvocation(left: CommandInvocation, right: CommandInvocation): number {
|
|
296
285
|
const id = compareText(left.commandId, right.commandId);
|
|
297
|
-
if (id !== 0)
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
);
|
|
301
|
-
const rightArguments = Object.entries(right.arguments).sort(([a], [b]) =>
|
|
302
|
-
compareText(a, b),
|
|
303
|
-
);
|
|
286
|
+
if (id !== 0) {
|
|
287
|
+
return id;
|
|
288
|
+
}
|
|
289
|
+
const leftArguments = Object.entries(left.arguments).sort(([a], [b]) => compareText(a, b));
|
|
290
|
+
const rightArguments = Object.entries(right.arguments).sort(([a], [b]) => compareText(a, b));
|
|
304
291
|
const length = Math.min(leftArguments.length, rightArguments.length);
|
|
305
292
|
for (let index = 0; index < length; index += 1) {
|
|
306
|
-
const
|
|
307
|
-
const
|
|
293
|
+
const leftArgument = leftArguments[index];
|
|
294
|
+
const rightArgument = rightArguments[index];
|
|
295
|
+
if (leftArgument === undefined || rightArgument === undefined) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
const [leftId, leftValue] = leftArgument;
|
|
299
|
+
const [rightId, rightValue] = rightArgument;
|
|
308
300
|
const field = compareText(leftId, rightId);
|
|
309
|
-
if (field !== 0)
|
|
301
|
+
if (field !== 0) {
|
|
302
|
+
return field;
|
|
303
|
+
}
|
|
310
304
|
const value = compareArgumentValue(leftValue, rightValue);
|
|
311
|
-
if (value !== 0)
|
|
305
|
+
if (value !== 0) {
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
312
308
|
}
|
|
313
309
|
return leftArguments.length - rightArguments.length;
|
|
314
310
|
}
|
|
@@ -325,7 +321,9 @@ function compareArgumentValue(
|
|
|
325
321
|
enum: 4,
|
|
326
322
|
} as const;
|
|
327
323
|
const rank = ranks[left.kind] - ranks[right.kind];
|
|
328
|
-
if (rank !== 0)
|
|
324
|
+
if (rank !== 0) {
|
|
325
|
+
return rank;
|
|
326
|
+
}
|
|
329
327
|
if (
|
|
330
328
|
(left.kind === "number" || left.kind === "integer") &&
|
|
331
329
|
(right.kind === "number" || right.kind === "integer")
|
|
@@ -339,14 +337,19 @@ function compareArgumentValue(
|
|
|
339
337
|
}
|
|
340
338
|
|
|
341
339
|
function compareText(left: string, right: string): number {
|
|
342
|
-
const leftValues =
|
|
343
|
-
const rightValues =
|
|
340
|
+
const leftValues = Array.from(left);
|
|
341
|
+
const rightValues = Array.from(right);
|
|
344
342
|
const length = Math.min(leftValues.length, rightValues.length);
|
|
345
343
|
for (let index = 0; index < length; index += 1) {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
344
|
+
const leftCode = leftValues[index]?.codePointAt(0);
|
|
345
|
+
const rightCode = rightValues[index]?.codePointAt(0);
|
|
346
|
+
if (leftCode === undefined || rightCode === undefined) {
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
const difference = leftCode - rightCode;
|
|
350
|
+
if (difference !== 0) {
|
|
351
|
+
return difference;
|
|
352
|
+
}
|
|
350
353
|
}
|
|
351
354
|
return leftValues.length - rightValues.length;
|
|
352
355
|
}
|
package/src/commands/ports.ts
CHANGED
|
@@ -19,25 +19,19 @@ export interface CommandSnapshotPort<Snapshot> {
|
|
|
19
19
|
listen?(invalidate: () => void): CommandUnlisten | Promise<CommandUnlisten>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// oxlint-disable-next-line typescript/no-empty-object-type -- This public interface permits consumer declaration merging.
|
|
23
|
+
export interface CommandCataloguePort extends CommandSnapshotPort<CommandCatalogueSnapshot> {}
|
|
24
24
|
|
|
25
|
-
export interface CommandKeymapPort
|
|
26
|
-
extends CommandSnapshotPort<CommandKeymapLoadOutcome> {
|
|
25
|
+
export interface CommandKeymapPort extends CommandSnapshotPort<CommandKeymapLoadOutcome> {
|
|
27
26
|
preview?(request: CommandKeymapPreview): Promise<CommandKeymapPreviewResult>;
|
|
28
27
|
commit?(request: CommandKeymapCommit): Promise<CommandKeymapMutationResult>;
|
|
29
28
|
reset?(request: CommandKeymapReset): Promise<CommandKeymapMutationResult>;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// oxlint-disable-next-line typescript/no-empty-object-type -- This public interface permits consumer declaration merging.
|
|
32
|
+
export interface CommandAvailabilityPort extends CommandSnapshotPort<CommandAvailabilitySnapshot> {}
|
|
34
33
|
|
|
35
|
-
export type CommandExecutionSource =
|
|
36
|
-
| "palette"
|
|
37
|
-
| "keyboard"
|
|
38
|
-
| "menu"
|
|
39
|
-
| "help"
|
|
40
|
-
| "consumer";
|
|
34
|
+
export type CommandExecutionSource = "palette" | "keyboard" | "menu" | "help" | "consumer";
|
|
41
35
|
|
|
42
36
|
export interface CommandExecutionIntent {
|
|
43
37
|
readonly requestId: CommandRequestId;
|
|
@@ -23,25 +23,25 @@ export interface CommandProjectionRecord {
|
|
|
23
23
|
readonly id: CommandId;
|
|
24
24
|
readonly label: string;
|
|
25
25
|
readonly description: string | null;
|
|
26
|
-
readonly categoryPath:
|
|
27
|
-
readonly keywords:
|
|
26
|
+
readonly categoryPath: ReadonlyArray<string>;
|
|
27
|
+
readonly keywords: ReadonlyArray<string>;
|
|
28
28
|
readonly icon: string | null;
|
|
29
29
|
readonly availability: CommandAvailability;
|
|
30
|
-
readonly shortcuts:
|
|
30
|
+
readonly shortcuts: ReadonlyArray<CommandShortcutRecord>;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface CommandSettingsRecord extends CommandProjectionRecord {
|
|
34
|
-
readonly bindings:
|
|
34
|
+
readonly bindings: ReadonlyArray<CommandEffectiveBinding>;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export interface CommandSurfaceProjection {
|
|
38
|
-
readonly palette:
|
|
39
|
-
readonly menu:
|
|
40
|
-
readonly help:
|
|
41
|
-
readonly settings:
|
|
42
|
-
readonly shortcuts:
|
|
43
|
-
readonly reverseLookup: ReadonlyMap<CommandId,
|
|
44
|
-
readonly conflicts:
|
|
38
|
+
readonly palette: ReadonlyArray<CommandProjectionRecord>;
|
|
39
|
+
readonly menu: ReadonlyArray<CommandProjectionRecord>;
|
|
40
|
+
readonly help: ReadonlyArray<CommandProjectionRecord>;
|
|
41
|
+
readonly settings: ReadonlyArray<CommandSettingsRecord>;
|
|
42
|
+
readonly shortcuts: ReadonlyArray<CommandShortcutRecord>;
|
|
43
|
+
readonly reverseLookup: ReadonlyMap<CommandId, ReadonlyArray<CommandShortcutRecord>>;
|
|
44
|
+
readonly conflicts: ReadonlyArray<CommandKeymapConflict>;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const AVAILABLE: CommandAvailability = {
|
|
@@ -63,9 +63,7 @@ export function joinCommandState(
|
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
65
|
if (keymap.registryDigest !== catalogue.registryDigest) {
|
|
66
|
-
throw new CommandProjectionConsistencyError(
|
|
67
|
-
"catalogue and keymap registry digests differ",
|
|
68
|
-
);
|
|
66
|
+
throw new CommandProjectionConsistencyError("catalogue and keymap registry digests differ");
|
|
69
67
|
}
|
|
70
68
|
const known = new Set(catalogue.commands.map(({ id }) => id));
|
|
71
69
|
const records = new Set<string>();
|
|
@@ -90,13 +88,10 @@ export function projectCommandSurfaces(
|
|
|
90
88
|
platform: CommandPlatform,
|
|
91
89
|
): CommandSurfaceProjection {
|
|
92
90
|
const availability = new Map(
|
|
93
|
-
state.availability.records.map((record) => [
|
|
94
|
-
record.commandId,
|
|
95
|
-
record.availability,
|
|
96
|
-
]),
|
|
91
|
+
state.availability.records.map((record) => [record.commandId, record.availability]),
|
|
97
92
|
);
|
|
98
|
-
const reverseLookup = new Map<CommandId,
|
|
99
|
-
const shortcuts: CommandShortcutRecord
|
|
93
|
+
const reverseLookup = new Map<CommandId, ReadonlyArray<CommandShortcutRecord>>();
|
|
94
|
+
const shortcuts: Array<CommandShortcutRecord> = [];
|
|
100
95
|
for (const command of state.catalogue.commands) {
|
|
101
96
|
const records = shortcutsForCommand(state.keymap, command.id, platform);
|
|
102
97
|
reverseLookup.set(command.id, records);
|
|
@@ -112,9 +107,7 @@ export function projectCommandSurfaces(
|
|
|
112
107
|
availability: availability.get(record.id) ?? AVAILABLE,
|
|
113
108
|
shortcuts: reverseLookup.get(record.id) ?? [],
|
|
114
109
|
});
|
|
115
|
-
const visible = state.catalogue.commands.filter(
|
|
116
|
-
({ visibility }) => !visibility.hidden,
|
|
117
|
-
);
|
|
110
|
+
const visible = state.catalogue.commands.filter(({ visibility }) => !visibility.hidden);
|
|
118
111
|
return {
|
|
119
112
|
palette: visible
|
|
120
113
|
.filter(({ visibility }) => visibility.palette)
|
|
@@ -143,10 +136,13 @@ export function projectCommandSurfaces(
|
|
|
143
136
|
}
|
|
144
137
|
|
|
145
138
|
export function searchCommands(
|
|
146
|
-
records:
|
|
139
|
+
records: ReadonlyArray<CommandDiscoveryRecord>,
|
|
147
140
|
query: string,
|
|
148
|
-
):
|
|
149
|
-
const terms = query
|
|
141
|
+
): ReadonlyArray<CommandSearchHit> {
|
|
142
|
+
const terms = query
|
|
143
|
+
.split(/\s+/u)
|
|
144
|
+
.filter(Boolean)
|
|
145
|
+
.map((term) => term.toLowerCase());
|
|
150
146
|
return records
|
|
151
147
|
.flatMap((record) => {
|
|
152
148
|
const score = scoreRecord(record, terms);
|
|
@@ -155,10 +151,7 @@ export function searchCommands(
|
|
|
155
151
|
.sort(
|
|
156
152
|
(left, right) =>
|
|
157
153
|
left.score - right.score ||
|
|
158
|
-
compareUnicodeScalars(
|
|
159
|
-
left.record.label.toLowerCase(),
|
|
160
|
-
right.record.label.toLowerCase(),
|
|
161
|
-
) ||
|
|
154
|
+
compareUnicodeScalars(left.record.label.toLowerCase(), right.record.label.toLowerCase()) ||
|
|
162
155
|
compareUnicodeScalars(left.record.id, right.record.id),
|
|
163
156
|
);
|
|
164
157
|
}
|
|
@@ -167,12 +160,11 @@ export function shortcutsForCommand(
|
|
|
167
160
|
keymap: CommandKeymapSnapshot,
|
|
168
161
|
commandId: CommandId,
|
|
169
162
|
platform: CommandPlatform,
|
|
170
|
-
):
|
|
163
|
+
): ReadonlyArray<CommandShortcutRecord> {
|
|
171
164
|
return keymap.bindings
|
|
172
165
|
.filter(
|
|
173
166
|
(binding) =>
|
|
174
|
-
binding.invocation.commandId === commandId &&
|
|
175
|
-
includesPlatform(binding.platform, platform),
|
|
167
|
+
binding.invocation.commandId === commandId && includesPlatform(binding.platform, platform),
|
|
176
168
|
)
|
|
177
169
|
.map((binding) => {
|
|
178
170
|
const chord = resolveTrigger(binding, platform);
|
|
@@ -186,10 +178,7 @@ export function shortcutsForCommand(
|
|
|
186
178
|
});
|
|
187
179
|
}
|
|
188
180
|
|
|
189
|
-
export function shortcutLabel(
|
|
190
|
-
chord: CommandKeyChord,
|
|
191
|
-
platform: CommandPlatform,
|
|
192
|
-
): string {
|
|
181
|
+
export function shortcutLabel(chord: CommandKeyChord, platform: CommandPlatform): string {
|
|
193
182
|
const key = keyLabel(chord.code);
|
|
194
183
|
if (platform === "macOs") {
|
|
195
184
|
return [
|
|
@@ -220,9 +209,11 @@ export class CommandProjectionConsistencyError extends Error {
|
|
|
220
209
|
|
|
221
210
|
function scoreRecord(
|
|
222
211
|
record: CommandDiscoveryRecord,
|
|
223
|
-
terms:
|
|
212
|
+
terms: ReadonlyArray<string>,
|
|
224
213
|
): number | undefined {
|
|
225
|
-
if (terms.length === 0)
|
|
214
|
+
if (terms.length === 0) {
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
226
217
|
const label = record.label.toLowerCase();
|
|
227
218
|
const description = record.description?.toLowerCase() ?? "";
|
|
228
219
|
const keywords = record.keywords.map((keyword) => keyword.toLowerCase());
|
|
@@ -248,8 +239,10 @@ function scoreRecord(
|
|
|
248
239
|
: description.includes(term)
|
|
249
240
|
? 80
|
|
250
241
|
: undefined;
|
|
251
|
-
if (termScore === undefined)
|
|
252
|
-
|
|
242
|
+
if (termScore === undefined) {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
score = Math.min(0xff_ff_ff_ff, score + termScore);
|
|
253
246
|
}
|
|
254
247
|
return score;
|
|
255
248
|
}
|
|
@@ -280,8 +273,12 @@ function resolveTrigger(
|
|
|
280
273
|
}
|
|
281
274
|
|
|
282
275
|
function keyLabel(code: string): string {
|
|
283
|
-
if (code.length === 4 && code.startsWith("Key"))
|
|
284
|
-
|
|
276
|
+
if (code.length === 4 && code.startsWith("Key")) {
|
|
277
|
+
return code.slice(3);
|
|
278
|
+
}
|
|
279
|
+
if (code.length === 6 && code.startsWith("Digit")) {
|
|
280
|
+
return code.slice(5);
|
|
281
|
+
}
|
|
285
282
|
return (
|
|
286
283
|
{
|
|
287
284
|
ArrowUp: "↑",
|
|
@@ -294,13 +291,18 @@ function keyLabel(code: string): string {
|
|
|
294
291
|
}
|
|
295
292
|
|
|
296
293
|
function compareUnicodeScalars(left: string, right: string): number {
|
|
297
|
-
const leftValues =
|
|
298
|
-
const rightValues =
|
|
294
|
+
const leftValues = Array.from(left);
|
|
295
|
+
const rightValues = Array.from(right);
|
|
299
296
|
const length = Math.min(leftValues.length, rightValues.length);
|
|
300
297
|
for (let index = 0; index < length; index += 1) {
|
|
301
|
-
const leftCode = leftValues[index]
|
|
302
|
-
const rightCode = rightValues[index]
|
|
303
|
-
if (leftCode
|
|
298
|
+
const leftCode = leftValues[index]?.codePointAt(0);
|
|
299
|
+
const rightCode = rightValues[index]?.codePointAt(0);
|
|
300
|
+
if (leftCode === undefined || rightCode === undefined) {
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
if (leftCode !== rightCode) {
|
|
304
|
+
return leftCode - rightCode;
|
|
305
|
+
}
|
|
304
306
|
}
|
|
305
307
|
return leftValues.length - rightValues.length;
|
|
306
308
|
}
|