@omercnet/paseo-shared-browser 4.1.12-next.505.1 → 4.1.12-next.513.1
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.
|
@@ -48,15 +48,20 @@ function fakeDom() {
|
|
|
48
48
|
removeEventListener: nodeTarget.remove,
|
|
49
49
|
} as unknown as KeyboardCanvasNode;
|
|
50
50
|
sink.focus();
|
|
51
|
+
/** Dispatches to the adapter's listeners; returns whether one cancelled the default. */
|
|
51
52
|
const fire = (name: string, type: string, event: object = {}) => {
|
|
53
|
+
let cancelled = false;
|
|
52
54
|
for (const listener of registry.get(`${name}:${type}`) ?? [])
|
|
53
55
|
(listener as (event: object) => void)({
|
|
54
|
-
preventDefault() {
|
|
56
|
+
preventDefault() {
|
|
57
|
+
cancelled = true;
|
|
58
|
+
},
|
|
55
59
|
stopPropagation() {},
|
|
56
60
|
...event,
|
|
57
61
|
});
|
|
62
|
+
return cancelled;
|
|
58
63
|
};
|
|
59
|
-
return { node, document, fire };
|
|
64
|
+
return { node, document, sink, fire };
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
const key = {
|
|
@@ -225,3 +230,181 @@ describe("web canvas keyboard adapter Android IME sequences", () => {
|
|
|
225
230
|
expect(texts(dom)).toEqual(["x"]);
|
|
226
231
|
});
|
|
227
232
|
});
|
|
233
|
+
|
|
234
|
+
type Bound = ReturnType<typeof bind>;
|
|
235
|
+
/** Remote key edges, such as "down:Backspace". */
|
|
236
|
+
const presses = (dom: Bound) =>
|
|
237
|
+
dom.events.flatMap((event) => (event.kind === "key" ? [`${event.type}:${event.key}`] : []));
|
|
238
|
+
const BACKSPACE = ["down:Backspace", "up:Backspace"];
|
|
239
|
+
|
|
240
|
+
/** keydown 229, one beforeinput edit, keyup 229, regardless of what the sink holds. */
|
|
241
|
+
function imeEdit(dom: Bound, inputType: string) {
|
|
242
|
+
dom.fire("sink", "keydown", ime);
|
|
243
|
+
dom.fire("sink", "beforeinput", { inputType, data: null });
|
|
244
|
+
dom.fire("doc", "keyup", ime);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Chrome Android applying a soft-keyboard Backspace (ImeAdapterImpl
|
|
249
|
+
* deleteSurroundingText): keydown 229; only when the sink has text before the
|
|
250
|
+
* caret, beforeinput deleteContentBackward, the deletion and input; keyup 229.
|
|
251
|
+
* Blink applies this deletion even when beforeinput is cancelled
|
|
252
|
+
* (InputMethodController::DeleteSelectionWithoutAdjustment ignores the result);
|
|
253
|
+
* cancelHonored covers an engine that does honor it.
|
|
254
|
+
*/
|
|
255
|
+
function softBackspace(dom: Bound, cancelHonored = false) {
|
|
256
|
+
dom.fire("sink", "keydown", ime);
|
|
257
|
+
if (dom.sink.value.length > 0) {
|
|
258
|
+
const cancelled = dom.fire("sink", "beforeinput", {
|
|
259
|
+
inputType: "deleteContentBackward",
|
|
260
|
+
data: null,
|
|
261
|
+
});
|
|
262
|
+
if (!cancelled || !cancelHonored) {
|
|
263
|
+
dom.sink.value = dom.sink.value.slice(0, -1);
|
|
264
|
+
dom.fire("sink", "input", { inputType: "deleteContentBackward", data: null });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
dom.fire("doc", "keyup", ime);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Hangul composition steps; Backspace inside it rewrites the composition. */
|
|
271
|
+
function compose(dom: Bound, steps: Array<{ inputType: string; data: string | null }>) {
|
|
272
|
+
dom.fire("sink", "keydown", ime);
|
|
273
|
+
dom.fire("sink", "compositionstart", { data: "" });
|
|
274
|
+
for (const [index, step] of steps.entries()) {
|
|
275
|
+
if (index > 0) dom.fire("sink", "keydown", { ...ime, isComposing: true });
|
|
276
|
+
dom.fire("sink", "beforeinput", step);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
describe("web canvas keyboard adapter Android soft-keyboard deletion", () => {
|
|
281
|
+
it.each<[string, (dom: Bound) => void, { texts: string[]; presses: string[] }]>([
|
|
282
|
+
[
|
|
283
|
+
"keydown 229 + beforeinput deleteContentBackward presses Backspace",
|
|
284
|
+
(dom) => imeEdit(dom, "deleteContentBackward"),
|
|
285
|
+
{ texts: [], presses: BACKSPACE },
|
|
286
|
+
],
|
|
287
|
+
[
|
|
288
|
+
"keydown 229 + beforeinput deleteContentForward presses Delete",
|
|
289
|
+
(dom) => imeEdit(dom, "deleteContentForward"),
|
|
290
|
+
{ texts: [], presses: ["down:Delete", "up:Delete"] },
|
|
291
|
+
],
|
|
292
|
+
// Word deletion has no host-independent shortcut (Ctrl or Option+Backspace).
|
|
293
|
+
[
|
|
294
|
+
"keydown 229 + beforeinput deleteWordBackward stays unmapped",
|
|
295
|
+
(dom) => imeEdit(dom, "deleteWordBackward"),
|
|
296
|
+
{ texts: [], presses: [] },
|
|
297
|
+
],
|
|
298
|
+
[
|
|
299
|
+
"keydown 229 + beforeinput deleteWordForward stays unmapped",
|
|
300
|
+
(dom) => imeEdit(dom, "deleteWordForward"),
|
|
301
|
+
{ texts: [], presses: [] },
|
|
302
|
+
],
|
|
303
|
+
[
|
|
304
|
+
"Backspace before any typing (empty field, keydown carries no key)",
|
|
305
|
+
(dom) => softBackspace(dom),
|
|
306
|
+
{ texts: [], presses: BACKSPACE },
|
|
307
|
+
],
|
|
308
|
+
[
|
|
309
|
+
"three Backspaces after a committed word",
|
|
310
|
+
(dom) => {
|
|
311
|
+
composeWord(dom, "hi");
|
|
312
|
+
for (let count = 0; count < 3; count += 1) softBackspace(dom);
|
|
313
|
+
},
|
|
314
|
+
{ texts: ["hi"], presses: [...BACKSPACE, ...BACKSPACE, ...BACKSPACE] },
|
|
315
|
+
],
|
|
316
|
+
[
|
|
317
|
+
"three Backspaces when the engine honors the cancelled beforeinput",
|
|
318
|
+
(dom) => {
|
|
319
|
+
composeWord(dom, "hi");
|
|
320
|
+
for (let count = 0; count < 3; count += 1) softBackspace(dom, true);
|
|
321
|
+
},
|
|
322
|
+
{ texts: ["hi"], presses: [...BACKSPACE, ...BACKSPACE, ...BACKSPACE] },
|
|
323
|
+
],
|
|
324
|
+
[
|
|
325
|
+
"Backspace after a non-composing insertText",
|
|
326
|
+
(dom) => {
|
|
327
|
+
dom.fire("sink", "keydown", ime);
|
|
328
|
+
dom.fire("sink", "beforeinput", { inputType: "insertText", data: "a" });
|
|
329
|
+
softBackspace(dom);
|
|
330
|
+
},
|
|
331
|
+
{ texts: ["a"], presses: BACKSPACE },
|
|
332
|
+
],
|
|
333
|
+
[
|
|
334
|
+
"Backspace after a paste",
|
|
335
|
+
(dom) => {
|
|
336
|
+
dom.fire("sink", "paste", { clipboardData: { getData: () => "pasted" } });
|
|
337
|
+
softBackspace(dom);
|
|
338
|
+
},
|
|
339
|
+
{ texts: ["pasted"], presses: BACKSPACE },
|
|
340
|
+
],
|
|
341
|
+
[
|
|
342
|
+
"Backspace after a control reset",
|
|
343
|
+
(dom) => {
|
|
344
|
+
dom.binding.reset();
|
|
345
|
+
softBackspace(dom);
|
|
346
|
+
},
|
|
347
|
+
{ texts: [], presses: BACKSPACE },
|
|
348
|
+
],
|
|
349
|
+
[
|
|
350
|
+
"Backspace inside a composing word edits it locally (Gboard predictive)",
|
|
351
|
+
(dom) => {
|
|
352
|
+
compose(dom, [
|
|
353
|
+
{ inputType: "insertCompositionText", data: "hel" },
|
|
354
|
+
{ inputType: "insertCompositionText", data: "he" },
|
|
355
|
+
]);
|
|
356
|
+
dom.fire("sink", "compositionend", { data: "he" });
|
|
357
|
+
},
|
|
358
|
+
{ texts: ["he"], presses: [] },
|
|
359
|
+
],
|
|
360
|
+
[
|
|
361
|
+
"Hangul: Backspace removes a jamo inside the composition",
|
|
362
|
+
(dom) => {
|
|
363
|
+
compose(dom, [
|
|
364
|
+
{ inputType: "insertCompositionText", data: "ㅎ" },
|
|
365
|
+
{ inputType: "insertCompositionText", data: "하" },
|
|
366
|
+
{ inputType: "insertCompositionText", data: "한" },
|
|
367
|
+
{ inputType: "insertCompositionText", data: "하" },
|
|
368
|
+
]);
|
|
369
|
+
dom.fire("sink", "compositionend", { data: "하" });
|
|
370
|
+
},
|
|
371
|
+
{ texts: ["하"], presses: [] },
|
|
372
|
+
],
|
|
373
|
+
[
|
|
374
|
+
"Hangul: Backspace empties the composition, then deletes the committed syllable",
|
|
375
|
+
(dom) => {
|
|
376
|
+
composeWord(dom, "한");
|
|
377
|
+
compose(dom, [
|
|
378
|
+
{ inputType: "insertCompositionText", data: "ㄱ" },
|
|
379
|
+
{ inputType: "deleteCompositionText", data: null },
|
|
380
|
+
]);
|
|
381
|
+
dom.fire("sink", "compositionend", { data: "" });
|
|
382
|
+
softBackspace(dom);
|
|
383
|
+
},
|
|
384
|
+
{ texts: ["한"], presses: BACKSPACE },
|
|
385
|
+
],
|
|
386
|
+
[
|
|
387
|
+
"a real Backspace keydown (keyCode 8) presses once even if beforeinput follows",
|
|
388
|
+
(dom) => {
|
|
389
|
+
const backspace = { ...key, key: "Backspace", code: "Backspace", keyCode: 8 };
|
|
390
|
+
dom.fire("sink", "keydown", backspace);
|
|
391
|
+
dom.fire("sink", "beforeinput", { inputType: "deleteContentBackward", data: null });
|
|
392
|
+
dom.fire("doc", "keyup", backspace);
|
|
393
|
+
},
|
|
394
|
+
{ texts: [], presses: BACKSPACE },
|
|
395
|
+
],
|
|
396
|
+
[
|
|
397
|
+
"an IME deletion after a control reset is dropped",
|
|
398
|
+
(dom) => {
|
|
399
|
+
dom.fire("sink", "keydown", ime);
|
|
400
|
+
dom.binding.reset();
|
|
401
|
+
dom.fire("sink", "beforeinput", { inputType: "deleteContentBackward", data: null });
|
|
402
|
+
},
|
|
403
|
+
{ texts: [], presses: [] },
|
|
404
|
+
],
|
|
405
|
+
])("%s", (_name, replay, expected) => {
|
|
406
|
+
const dom = bind();
|
|
407
|
+
replay(dom);
|
|
408
|
+
expect({ texts: texts(dom), presses: presses(dom) }).toEqual(expected);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
@@ -57,6 +57,18 @@ interface BindingOptions {
|
|
|
57
57
|
onError(error: Error): void;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// Android soft keyboards delete through InputConnection.deleteSurroundingText.
|
|
61
|
+
// Chrome reports keydown 229/"Unidentified", then beforeinput delete* only when
|
|
62
|
+
// the sink has text next to the caret. With an empty sink the keydown and keyup
|
|
63
|
+
// are all that arrive, so the sink always keeps one invisible character to delete.
|
|
64
|
+
const SINK_TEXT = "\u200B";
|
|
65
|
+
// Character deletions map to the key a hardware keyboard sends. Word deletions
|
|
66
|
+
// stay unmapped: the remote shortcut depends on the host OS (Ctrl or Option).
|
|
67
|
+
const IME_EDIT_KEYS: Record<string, string> = {
|
|
68
|
+
deleteContentBackward: "Backspace",
|
|
69
|
+
deleteContentForward: "Delete",
|
|
70
|
+
};
|
|
71
|
+
|
|
60
72
|
/** DOM-only binding; callers must dispose it and reset on route/control changes. */
|
|
61
73
|
export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: BindingOptions) {
|
|
62
74
|
const document = node.ownerDocument;
|
|
@@ -80,13 +92,14 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
|
|
|
80
92
|
});
|
|
81
93
|
node.tabIndex = 0;
|
|
82
94
|
node.appendChild(sink);
|
|
95
|
+
sink.value = SINK_TEXT;
|
|
83
96
|
let composing = false;
|
|
84
97
|
let compositionAdmitted = false;
|
|
85
98
|
let altTextPending: string | null = null;
|
|
86
|
-
// Soft keyboards (Android Chrome) report
|
|
87
|
-
//
|
|
88
|
-
// keydown 229/"Unidentified" followed by beforeinput insertText
|
|
89
|
-
// carries no key to forward, so the
|
|
99
|
+
// Soft keyboards (Android Chrome) report edits outside a composition, such as
|
|
100
|
+
// a space after a word, every key on non-predictive keyboards, or Backspace,
|
|
101
|
+
// as keydown 229/"Unidentified" followed by beforeinput insertText or delete*.
|
|
102
|
+
// That keydown carries no key to forward, so the edit itself is the only source.
|
|
90
103
|
let imeTextPending = false;
|
|
91
104
|
const focused = () => document.activeElement === sink || document.activeElement === node;
|
|
92
105
|
const keyboard = createBrowserCanvasKeyboard({
|
|
@@ -103,7 +116,7 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
|
|
|
103
116
|
composing = false;
|
|
104
117
|
altTextPending = null;
|
|
105
118
|
imeTextPending = false;
|
|
106
|
-
sink.value =
|
|
119
|
+
sink.value = SINK_TEXT;
|
|
107
120
|
};
|
|
108
121
|
const cancel = () => {
|
|
109
122
|
reset();
|
|
@@ -177,12 +190,31 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
|
|
|
177
190
|
if (accepted) {
|
|
178
191
|
commitText(event.data ?? "");
|
|
179
192
|
}
|
|
180
|
-
sink.value =
|
|
193
|
+
sink.value = SINK_TEXT;
|
|
194
|
+
};
|
|
195
|
+
// One full press, as the matching hardware key would send it.
|
|
196
|
+
const pressKey = (key: string) => {
|
|
197
|
+
const press = {
|
|
198
|
+
key,
|
|
199
|
+
code: key,
|
|
200
|
+
altKey: false,
|
|
201
|
+
ctrlKey: false,
|
|
202
|
+
metaKey: false,
|
|
203
|
+
shiftKey: false,
|
|
204
|
+
repeat: false,
|
|
205
|
+
};
|
|
206
|
+
if (keyboard.key("down", press)) {
|
|
207
|
+
keyboard.key("up", press);
|
|
208
|
+
}
|
|
181
209
|
};
|
|
182
210
|
const beforeInput = (event: KeyboardDomEvent) => {
|
|
183
211
|
if (!composing && options.enabled() && focused()) {
|
|
184
212
|
consume(event);
|
|
185
|
-
|
|
213
|
+
const editKey =
|
|
214
|
+
imeTextPending && event.inputType ? IME_EDIT_KEYS[event.inputType] : undefined;
|
|
215
|
+
if (editKey) {
|
|
216
|
+
pressKey(editKey);
|
|
217
|
+
} else if (
|
|
186
218
|
event.inputType === "insertText" &&
|
|
187
219
|
event.data &&
|
|
188
220
|
(imeTextPending || event.data === altTextPending)
|
|
@@ -192,6 +224,13 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
|
|
|
192
224
|
altTextPending = null;
|
|
193
225
|
}
|
|
194
226
|
};
|
|
227
|
+
// Blink applies a deleteSurroundingText deletion even when its beforeinput was
|
|
228
|
+
// cancelled. Put the sink text back so the next Backspace still has a target.
|
|
229
|
+
const input = () => {
|
|
230
|
+
if (!composing && sink.value !== SINK_TEXT) {
|
|
231
|
+
sink.value = SINK_TEXT;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
195
234
|
const paste = (event: KeyboardDomEvent) => {
|
|
196
235
|
if (!options.enabled() || !focused()) {
|
|
197
236
|
return;
|
|
@@ -199,7 +238,7 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
|
|
|
199
238
|
consume(event);
|
|
200
239
|
altTextPending = null;
|
|
201
240
|
commitText(event.clipboardData?.getData("text/plain") ?? "");
|
|
202
|
-
sink.value =
|
|
241
|
+
sink.value = SINK_TEXT;
|
|
203
242
|
};
|
|
204
243
|
const visibility = () => {
|
|
205
244
|
if (document.hidden) {
|
|
@@ -216,6 +255,7 @@ export function bindBrowserCanvasKeyboard(node: KeyboardCanvasNode, options: Bin
|
|
|
216
255
|
[sink, "compositionstart", compositionStart],
|
|
217
256
|
[sink, "compositionend", compositionEnd],
|
|
218
257
|
[sink, "beforeinput", beforeInput],
|
|
258
|
+
[sink, "input", input],
|
|
219
259
|
[sink, "paste", paste],
|
|
220
260
|
[sink, "blur", cancel],
|
|
221
261
|
];
|
|
@@ -396,6 +396,38 @@ describe("bounded browser input queue", () => {
|
|
|
396
396
|
expect(f.errors).toEqual([]);
|
|
397
397
|
});
|
|
398
398
|
|
|
399
|
+
it("sends soft-keyboard text queued behind an in-flight call as one insertion, never across keys", async () => {
|
|
400
|
+
const f = fixture();
|
|
401
|
+
const backspace = (type: "down" | "up"): BrowserGestureEvent => ({
|
|
402
|
+
kind: "key",
|
|
403
|
+
type,
|
|
404
|
+
key: "Backspace",
|
|
405
|
+
code: "Backspace",
|
|
406
|
+
modifiers: 0,
|
|
407
|
+
repeat: false,
|
|
408
|
+
});
|
|
409
|
+
for (const text of ["h", "e", "l", "l", "o"]) f.queue.enqueue({ kind: "text", text });
|
|
410
|
+
f.queue.enqueue(backspace("down"));
|
|
411
|
+
f.queue.enqueue(backspace("up"));
|
|
412
|
+
for (const text of [" ", "w"]) f.queue.enqueue({ kind: "text", text });
|
|
413
|
+
// Merging stops at the per-event text limit the server enforces.
|
|
414
|
+
f.queue.enqueue({ kind: "text", text: "x".repeat(15_999) });
|
|
415
|
+
f.queue.finish();
|
|
416
|
+
f.beginGate.resolve({ state, gestureId: "owned", nextSequence: 1 });
|
|
417
|
+
await flush();
|
|
418
|
+
expect(f.sent.map(({ event }) => (event.kind === "text" ? event.text : event.kind))).toEqual([
|
|
419
|
+
"h",
|
|
420
|
+
"ello",
|
|
421
|
+
"key",
|
|
422
|
+
"key",
|
|
423
|
+
" w",
|
|
424
|
+
"x".repeat(15_999),
|
|
425
|
+
]);
|
|
426
|
+
expect(f.sent.map((input) => input.sequence)).toEqual([1, 2, 3, 4, 5, 6]);
|
|
427
|
+
expect(f.ended[0]).toMatchObject({ sequence: 7, cancel: false });
|
|
428
|
+
expect(f.errors).toEqual([]);
|
|
429
|
+
});
|
|
430
|
+
|
|
399
431
|
it("keeps touch-ID edges through 60Hz motion and partial release", async () => {
|
|
400
432
|
const f = fixture();
|
|
401
433
|
const touch = (
|
|
@@ -84,6 +84,8 @@ export const BROWSER_INPUT_IDLE_MS = 4_000;
|
|
|
84
84
|
export const BROWSER_INPUT_KEEPALIVE_MS = 2_000;
|
|
85
85
|
const MAX_QUEUED_COMMANDS = 64;
|
|
86
86
|
const MAX_WHEEL_DELTA = 4_000;
|
|
87
|
+
/** Per-event text limit the gesture schema and runtime owner enforce. */
|
|
88
|
+
const MAX_TEXT_LENGTH = 16_000;
|
|
87
89
|
const MAX_FRAME_ADMISSION_ATTEMPTS = 3;
|
|
88
90
|
const FRAME_ADMISSION_WAIT_MS = 4_000;
|
|
89
91
|
|
|
@@ -551,6 +553,16 @@ export function createBrowserInputQueue(options: QueueOptions) {
|
|
|
551
553
|
return true;
|
|
552
554
|
}
|
|
553
555
|
}
|
|
556
|
+
// Soft keyboards commit text in small pieces, one update each. Text still
|
|
557
|
+
// queued behind the in-flight call is one insertion; never merge across keys.
|
|
558
|
+
if (
|
|
559
|
+
event.kind === "text" &&
|
|
560
|
+
previous.event.kind === "text" &&
|
|
561
|
+
previous.event.text.length + event.text.length <= MAX_TEXT_LENGTH
|
|
562
|
+
) {
|
|
563
|
+
previous.event = { kind: "text", text: previous.event.text + event.text };
|
|
564
|
+
return true;
|
|
565
|
+
}
|
|
554
566
|
}
|
|
555
567
|
if (commands.length >= MAX_QUEUED_COMMANDS) {
|
|
556
568
|
cancel();
|
package/package.json
CHANGED