From efe7db693504394052921cbe2a8740bb0d62c5a7 Mon Sep 17 00:00:00 2001 From: Amund Tenstad Date: Thu, 14 Nov 2024 08:00:09 +0100 Subject: [PATCH] fix: improved keycode extraction from title --- src/store/keycodes.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/store/keycodes.js b/src/store/keycodes.js index 7fe80d44b6..62515b7665 100644 --- a/src/store/keycodes.js +++ b/src/store/keycodes.js @@ -15,14 +15,35 @@ const keycodePickerTabLayout = { ISO_ANSI: [...iso_jis, ...ansi], special: [...quantum, ...settings, ...media], extra: Object.values(keymapExtras) - .map(({ keycodeLUT, prefix }) => - Object.entries(keycodeLUT).map(([code, { name, title }]) => ({ - code: title?.split(' ')[0], // split removes ' (dead)' - name, - language_prefix: prefix, - title: code - })) - ) + .map(({ keycodeLUT, prefix }) => { + const keycodes = []; + Object.entries(keycodeLUT).forEach(([code, { name, title }]) => { + if (title === undefined) { + return; + } + + let start = title.search(prefix + '_'); + if (start < 0) { + return; + } + + let end = start + prefix.length + 1; + while ( + end < title.length && + title.charCodeAt(end) >= 65 && + title.charCodeAt(end) <= 90 + ) { + end++; + } + keycodes.push({ + code: title.substring(start, end), + name, + language_prefix: prefix, + title: code + }); + }); + return keycodes; + }) .flat() };