Skip to content

Commit d359ae0

Browse files
committed
fix: paste-as-text on non-Latin layouts
1 parent 8b74a69 commit d359ae0

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { isPasteAsTextShortcut } from "./textPaste.ts";
4+
5+
describe("isPasteAsTextShortcut", () => {
6+
it("accepts the V key on non-Latin layouts but follows the letter on Latin ones", () => {
7+
const chord = { metaKey: false, ctrlKey: true, shiftKey: true, altKey: false };
8+
expect(isPasteAsTextShortcut({ ...chord, key: "М", code: "KeyV" }, false)).toBe(true);
9+
expect(isPasteAsTextShortcut({ ...chord, key: "k", code: "KeyV" }, false)).toBe(false);
10+
expect(isPasteAsTextShortcut({ ...chord, key: "V", code: "Period" }, false)).toBe(true);
11+
});
12+
});

‎packages/client-runtime/src/textPaste.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ const textEncoder = new TextEncoder();
44

55
export type PastedTextDisposition = "attachment" | "inline";
66

7+
/** Non-Latin layouts (Cyrillic, Greek) report the typed letter; fall back to the physical key. */
8+
function isVKey(event: { readonly key: string; readonly code?: string }): boolean {
9+
const key = event.key.toLowerCase();
10+
return /^[a-z]$/.test(key) ? key === "v" : event.code === "KeyV";
11+
}
12+
713
export function isPasteAsTextShortcut(
8-
event: Pick<KeyboardEvent, "key" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey">,
14+
event: Pick<KeyboardEvent, "key" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey"> & {
15+
readonly code?: string;
16+
},
917
macPlatform: boolean,
1018
): boolean {
1119
return (
12-
event.key.toLowerCase() === "v" &&
20+
isVKey(event) &&
1321
event.shiftKey &&
1422
!event.altKey &&
1523
(macPlatform ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey)

0 commit comments

Comments
 (0)