Skip to content

Commit 34f48f9

Browse files
committed
Improve error handling and pre-loading
1 parent 962a6f6 commit 34f48f9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ui/src/components/popovers/PasteModal.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ export default function PasteModal() {
3333
state => state.setKeyboardLayout,
3434
);
3535

36+
useEffect(() => {
37+
send("getKeyboardLayout", {}, resp => {
38+
if ("error" in resp) return;
39+
setKeyboardLayout(resp.result as string);
40+
});
41+
}, []);
42+
3643
const onCancelPasteMode = useCallback(() => {
3744
setPasteMode(false);
3845
setDisableVideoFocusTrap(false);
@@ -48,6 +55,9 @@ export default function PasteModal() {
4855

4956
try {
5057
for (const char of text) {
58+
if (!keyboardLayout) continue;
59+
if (!chars[keyboardLayout]) continue;
60+
5161
const { key, shift, altRight, space, capsLock, trema } = chars[keyboardLayout][char] ?? {};
5262
if (!key) continue;
5363

@@ -97,11 +107,6 @@ export default function PasteModal() {
97107
if (TextAreaRef.current) {
98108
TextAreaRef.current.focus();
99109
}
100-
101-
send("getKeyboardLayout", {}, resp => {
102-
if ("error" in resp) return;
103-
setKeyboardLayout(resp.result as string);
104-
});
105110
}, []);
106111

107112
return (

0 commit comments

Comments
 (0)