mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2025-12-13 06:16:16 +00:00
@@ -50,52 +50,54 @@
|
|||||||
onlyPhrase: boolean = false,
|
onlyPhrase: boolean = false,
|
||||||
) {
|
) {
|
||||||
const plainPhrase: string[] = [""];
|
const plainPhrase: string[] = [""];
|
||||||
const extraActions: string[] = [];
|
const tags = new Set<string>();
|
||||||
const extraCodes: string[] = [];
|
const extraActions = new Set<string>();
|
||||||
|
const extraCodes = new Set<string>();
|
||||||
|
|
||||||
for (const actionCode of chord.phrase ?? []) {
|
for (const actionCode of chord.phrase ?? []) {
|
||||||
const action = codes.get(actionCode);
|
const action = codes.get(actionCode);
|
||||||
if (!action) {
|
if (!action) {
|
||||||
extraCodes.push(`0x${actionCode.toString(16)}`);
|
extraCodes.add(`0x${actionCode.toString(16)}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const osCode = action.keyCode && osLayout.get(action.keyCode);
|
const osCode = action.keyCode && osLayout.get(action.keyCode);
|
||||||
const token = osCode?.length === 1 ? osCode : action.display || action.id;
|
const token = osCode?.length === 1 ? osCode : action.display || action.id;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
extraCodes.push(`0x${action.code.toString(16)}`);
|
extraCodes.add(`0x${action.code.toString(16)}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/^\s$/.test(token) && plainPhrase.at(-1) !== "") {
|
if (
|
||||||
|
(token === "SPACE" || /^\s$/.test(token)) &&
|
||||||
|
plainPhrase.at(-1) !== ""
|
||||||
|
) {
|
||||||
plainPhrase.push("");
|
plainPhrase.push("");
|
||||||
} else if (token.length === 1) {
|
} else if (token.length === 1) {
|
||||||
plainPhrase[plainPhrase.length - 1] =
|
plainPhrase[plainPhrase.length - 1] =
|
||||||
plainPhrase[plainPhrase.length - 1] + token;
|
plainPhrase[plainPhrase.length - 1] + token;
|
||||||
} else {
|
} else {
|
||||||
extraActions.push(token);
|
extraActions.add(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chord.phrase?.[0] === 298) {
|
if (chord.phrase?.[0] === 298) {
|
||||||
plainPhrase.push("suffix");
|
tags.add("suffix");
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
["ARROW_LT", "ARROW_RT", "ARROW_UP", "ARROW_DN"].some((it) =>
|
["ARROW_LT", "ARROW_RT", "ARROW_UP", "ARROW_DN"].some((it) =>
|
||||||
extraActions.includes(it),
|
extraActions.has(it),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
plainPhrase.push("cursor warp");
|
tags.add("cursor warp");
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
["CTRL", "ALT", "GUI", "ENTER", "TAB"].some((it) =>
|
["CTRL", "ALT", "GUI", "ENTER", "TAB"].some((it) => extraActions.has(it))
|
||||||
extraActions.includes(it),
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
plainPhrase.push("macro");
|
tags.add("macro");
|
||||||
}
|
}
|
||||||
if (chord.actions[0] !== 0) {
|
if (chord.actions[0] !== 0) {
|
||||||
plainPhrase.push("compound");
|
tags.add("compound");
|
||||||
}
|
}
|
||||||
|
|
||||||
const input = chord.actions
|
const input = chord.actions
|
||||||
@@ -109,14 +111,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (onlyPhrase) {
|
if (onlyPhrase) {
|
||||||
return plainPhrase.join();
|
return plainPhrase.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...plainPhrase,
|
...plainPhrase,
|
||||||
`+${input.join("+")}`,
|
`+${input.join("+")}`,
|
||||||
...new Set(extraActions),
|
...tags,
|
||||||
...new Set(extraCodes),
|
...extraActions,
|
||||||
|
...extraCodes,
|
||||||
].join(" ");
|
].join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user