From 34f48f9beaa9b48bc6fd965a72069a6183bfce50 Mon Sep 17 00:00:00 2001 From: Daniel Lorch Date: Fri, 2 May 2025 01:51:20 +0200 Subject: [PATCH] Improve error handling and pre-loading --- ui/src/components/popovers/PasteModal.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ui/src/components/popovers/PasteModal.tsx b/ui/src/components/popovers/PasteModal.tsx index 543af00..6d74004 100644 --- a/ui/src/components/popovers/PasteModal.tsx +++ b/ui/src/components/popovers/PasteModal.tsx @@ -33,6 +33,13 @@ export default function PasteModal() { state => state.setKeyboardLayout, ); + useEffect(() => { + send("getKeyboardLayout", {}, resp => { + if ("error" in resp) return; + setKeyboardLayout(resp.result as string); + }); + }, []); + const onCancelPasteMode = useCallback(() => { setPasteMode(false); setDisableVideoFocusTrap(false); @@ -48,6 +55,9 @@ export default function PasteModal() { try { for (const char of text) { + if (!keyboardLayout) continue; + if (!chars[keyboardLayout]) continue; + const { key, shift, altRight, space, capsLock, trema } = chars[keyboardLayout][char] ?? {}; if (!key) continue; @@ -97,11 +107,6 @@ export default function PasteModal() { if (TextAreaRef.current) { TextAreaRef.current.focus(); } - - send("getKeyboardLayout", {}, resp => { - if ("error" in resp) return; - setKeyboardLayout(resp.result as string); - }); }, []); return (