Skip to content

Commit e9e0e72

Browse files
kevin9327claudedavidmckayv
authored
Paste into a Bot's browser on a layout that does not write Latin letters (#596)
While a person drives a Bot's browser, Ctrl+V or Cmd+V stays in the local page so its paste event can carry the clipboard text across. isPasteShortcut compared KeyboardEvent.key with "v", and on Russian or Greek the V key writes "м" or "ω", so the keystroke was sent to the Bot's browser, the local paste was prevented, and nothing was pasted. It now reads the key through keyOf, the rule the app's shortcuts already use for those layouts. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: David McKay <david@copilotkit.ai>
1 parent 9da63c1 commit e9e0e72

4 files changed

Lines changed: 92 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.
88

99
## Unreleased
1010

11+
### Pasting into a Bot's browser works on a layout that does not write Latin letters
12+
13+
While somebody drives a Bot's browser, Ctrl+V or Cmd+V is left to the local page so its paste event
14+
can send the clipboard text across. The shortcut was recognised by the character the key writes,
15+
and on a Russian or Greek layout the V key writes "м" or "ω", so the keystroke went to the Bot's
16+
browser instead and nothing was pasted. The V is now read the way the app's own shortcuts read it
17+
since Shift+N was fixed for the same layouts: from the physical key when the layout writes a
18+
character outside ASCII there.
1119
### Reading a large file from Google Drive no longer downloads all of it
1220

1321
`read_file_content` shows a Bot at most the first 20,000 characters of a file, but it downloaded the

‎app/src/components/computer/live-screen.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useCallback, useEffect, useRef, useState } from "react";
2+
import { keyOf } from "@/lib/hotkeys/hotkeys";
23
import { socketUrl } from "@/lib/socket-url";
34
import { currentPageVisible } from "./preview-visibility";
45
import { pageCoordinates } from "./take-the-wheel";
@@ -33,9 +34,14 @@ function modifierBits(event: {
3334
);
3435
}
3536

36-
/** Let the local browser create a paste event, whose clipboard text is forwarded separately. */
37+
/**
38+
* Let the local browser create a paste event, whose clipboard text is forwarded separately.
39+
*
40+
* The V is read the way a shortcut is (`keyOf`), so a layout that writes another script still has
41+
* one: Ctrl and the V key report "м" on Russian and "ω" on Greek.
42+
*/
3743
function isPasteShortcut(event: KeyboardEvent): boolean {
38-
return (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "v";
44+
return (event.ctrlKey || event.metaKey) && keyOf(event) === "v";
3945
}
4046

4147
type Props = {

‎app/src/lib/hotkeys/hotkeys.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const isMac =
6161
* Latin N) on Greek, so a shortcut read from `key` alone never fired there. When `key` is a single
6262
* character outside ASCII, the physical key in `code` is the only N there is.
6363
*/
64-
function keyOf(event: KeyboardEvent): string {
64+
export function keyOf(event: KeyboardEvent): string {
6565
const written = event.key.toLowerCase();
6666
if (written.length !== 1 || written.charCodeAt(0) < 0x80) return written;
6767
const physical = /^(?:Key|Digit)([A-Z0-9])$/.exec(event.code);

‎app/tests/live-screen-keyboard.test.tsx‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,81 @@ for (const [name, modifier] of [
7575
});
7676
}
7777

78+
/*
79+
* A layout that writes another script has no key that writes a V. Ctrl and the V key report "м" on
80+
* Russian and "ω" on Greek, with `code` still `KeyV`, so reading `key` alone sent the shortcut to the
81+
* remote browser and stopped the local paste event that carries the clipboard text.
82+
*/
83+
for (const [layout, written] of [
84+
["Russian", "м"],
85+
["Greek", "ω"],
86+
] as const) {
87+
test(`Ctrl+V on a ${layout} layout stays in the local page too`, async () => {
88+
const socket = await liveSocket();
89+
const shortcut = new KeyboardEvent("keydown", {
90+
key: written,
91+
code: "KeyV",
92+
keyCode: 86,
93+
ctrlKey: true,
94+
bubbles: true,
95+
cancelable: true,
96+
});
97+
98+
window.dispatchEvent(shortcut);
99+
window.dispatchEvent(
100+
new KeyboardEvent("keyup", {
101+
key: written,
102+
code: "KeyV",
103+
keyCode: 86,
104+
bubbles: true,
105+
cancelable: true,
106+
}),
107+
);
108+
109+
expect(socket.sent).toEqual([]);
110+
expect(shortcut.defaultPrevented).toBe(false);
111+
});
112+
}
113+
114+
test("Ctrl on a key that writes V on Dvorak is still paste, and Ctrl on the QWERTY V key is not", async () => {
115+
const socket = await liveSocket();
116+
// On Dvorak the key that writes V is the one QWERTY calls Period.
117+
const paste = new KeyboardEvent("keydown", {
118+
key: "v",
119+
code: "Period",
120+
keyCode: 86,
121+
ctrlKey: true,
122+
bubbles: true,
123+
cancelable: true,
124+
});
125+
// And the key QWERTY calls V writes K.
126+
const other = new KeyboardEvent("keydown", {
127+
key: "k",
128+
code: "KeyV",
129+
keyCode: 75,
130+
ctrlKey: true,
131+
bubbles: true,
132+
cancelable: true,
133+
});
134+
135+
window.dispatchEvent(paste);
136+
window.dispatchEvent(other);
137+
138+
expect(paste.defaultPrevented).toBe(false);
139+
expect(other.defaultPrevented).toBe(true);
140+
expect(socket.sent).toEqual([
141+
{
142+
type: "key",
143+
event: "down",
144+
key: "k",
145+
code: "KeyV",
146+
text: "k",
147+
windowsVirtualKeyCode: 75,
148+
modifiers: 2,
149+
},
150+
]);
151+
});
152+
78153
test("a paste keyup stays local when the modifier was released first", async () => {
79154
const socket = await liveSocket();
80155
window.dispatchEvent(

0 commit comments

Comments
 (0)