Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(desktop): the physical V key pastes on non-Latin layouts too

AdityaUmale99db08ac5cc4
diff --git a/src/lib/desktop-connection.test.ts b/src/lib/desktop-connection.test.ts
index ab62da4fa3..ac7f624134 100644
--- a/src/lib/desktop-connection.test.ts
+++ b/src/lib/desktop-connection.test.ts
@@ -182,6 +182,15 @@ describe("pasting into a desktop", () => {
expect(client.keys).toEqual([[0xffe3, "ControlLeft", true], [0x76, "KeyV"], [0xffe3, "ControlLeft", false]]);
});
+ it("the V key pastes on a non-Latin layout too, but a Latin layout's other letter there stays a key", async () => {
+ const { client, forwarded, press, paste } = await desktop("win32");
+ press("м", { code: "KeyV", ctrlKey: true }); // Russian layout
+ press("k", { code: "KeyV", ctrlKey: true }); // Dvorak: Ctrl+K, not a paste
+ paste("Привет");
+ expect(forwarded).toEqual(["k"]);
+ expect(client.pasted).toEqual(["Привет"]);
+ });
+
it("other shortcuts still reach the desktop as keys: Ctrl+V on a Mac, ⌘⇧V", async () => {
const { client, forwarded, press } = await desktop("darwin");
press("v", { code: "KeyV", ctrlKey: true });
diff --git a/src/lib/desktop-connection.ts b/src/lib/desktop-connection.ts
index aa8cdc18a6..68b904e503 100644
--- a/src/lib/desktop-connection.ts
+++ b/src/lib/desktop-connection.ts
@@ -84,7 +84,7 @@ function forwardPaste(screen: HTMLElement, client: RFB, signal: AbortSignal): vo
screen.addEventListener("keydown", (event) => {
if (pasteModifier.test(event.code)) held = event.code;
const modifier = mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
- if (client.viewOnly || !modifier || event.altKey || event.shiftKey || event.key.toLowerCase() !== "v") return;
+ if (client.viewOnly || !modifier || event.altKey || event.shiftKey || !isPasteKey(event)) return;
event.stopPropagation();
}, { capture: true, signal });
screen.addEventListener("keyup", (event) => { if (event.code === held) held = null; }, { capture: true, signal });
@@ -95,6 +95,12 @@ function forwardPaste(screen: HTMLElement, client: RFB, signal: AbortSignal): vo
}, { signal });
}
+/** V, or the physical V key on a layout whose letter there isn't Latin (Russian "м"), as the browser itself pastes on. */
+function isPasteKey(event: KeyboardEvent): boolean {
+ const key = event.key.toLowerCase();
+ return key === "v" || (event.code === "KeyV" && !/^[a-z]$/.test(key));
+}
+
/** `held` is the modifier the person holds that noVNC already sent down: Ctrl stays down for their own release; a Mac's
* ⌘ is let go once Ctrl is down, so the desktop sees Ctrl+V and not a lone ⌘ tap. */
function pasteOnDesktop(client: RFB, text: string, held: string | null): void {