fix: normalize Unicode characters in paste modal for proper detection

Fixes #957 - Paste modal now correctly detects Spanish characters
requiring AltRight modifier (@, |, #) and accented characters (ñ)
by normalizing all input text to NFC form before keyboard layout
lookup.

Root cause: macOS and other sources may provide text in NFD
(decomposed) form while keyboard layouts store characters in NFC
(composed) form. JavaScript object property lookup requires exact
byte match, causing lookups to fail despite characters being defined.

Solution: Apply .normalize('NFC') to all user input characters before
validation and paste execution.

Testing: Browser-based validation testing completed with Spanish
keyboard layout (es-ES) using text from multiple sources (TextEdit,
Safari, Notes) on macOS. Hardware testing requires JetKVM device.
This commit is contained in:
Nitish Agarwal 2025-11-17 08:01:18 +05:30
parent b074462ee7
commit 1f79b7c737
1 changed files with 3 additions and 2 deletions

View File

@ -66,7 +66,8 @@ export default function PasteModal() {
const macroSteps: MacroStep[] = []; const macroSteps: MacroStep[] = [];
for (const char of text) { for (const char of text) {
const keyprops = selectedKeyboard.chars[char]; const normalizedChar = char.normalize('NFC');
const keyprops = selectedKeyboard.chars[normalizedChar];
if (!keyprops) continue; if (!keyprops) continue;
const { key, shift, altRight, deadKey, accentKey } = keyprops; const { key, shift, altRight, deadKey, accentKey } = keyprops;
@ -164,7 +165,7 @@ export default function PasteModal() {
...new Set( ...new Set(
// @ts-expect-error TS doesn't recognize Intl.Segmenter in some environments // @ts-expect-error TS doesn't recognize Intl.Segmenter in some environments
[...new Intl.Segmenter().segment(value)] [...new Intl.Segmenter().segment(value)]
.map(x => x.segment) .map(x => x.segment.normalize('NFC'))
.filter(char => !selectedKeyboard.chars[char]), .filter(char => !selectedKeyboard.chars[char]),
), ),
]; ];