Skip to content

Commit

Permalink
fix: improved keycode extraction from title
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad committed Nov 14, 2024
1 parent 67af324 commit efe7db6
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/store/keycodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand Down

0 comments on commit efe7db6

Please sign in to comment.