From 762f73063a162c9daff1759237730b07e66611c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Fri, 14 Feb 2025 13:33:44 +0100 Subject: [PATCH] fix: vocabulary is eating spaces fixes #115 --- src/routes/(app)/config/chords/+page.svelte | 37 +++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/routes/(app)/config/chords/+page.svelte b/src/routes/(app)/config/chords/+page.svelte index e8b01d51..9cd14aa6 100644 --- a/src/routes/(app)/config/chords/+page.svelte +++ b/src/routes/(app)/config/chords/+page.svelte @@ -50,52 +50,54 @@ onlyPhrase: boolean = false, ) { const plainPhrase: string[] = [""]; - const extraActions: string[] = []; - const extraCodes: string[] = []; + const tags = new Set(); + const extraActions = new Set(); + const extraCodes = new Set(); for (const actionCode of chord.phrase ?? []) { const action = codes.get(actionCode); if (!action) { - extraCodes.push(`0x${actionCode.toString(16)}`); + extraCodes.add(`0x${actionCode.toString(16)}`); continue; } const osCode = action.keyCode && osLayout.get(action.keyCode); const token = osCode?.length === 1 ? osCode : action.display || action.id; if (!token) { - extraCodes.push(`0x${action.code.toString(16)}`); + extraCodes.add(`0x${action.code.toString(16)}`); continue; } - if (/^\s$/.test(token) && plainPhrase.at(-1) !== "") { + if ( + (token === "SPACE" || /^\s$/.test(token)) && + plainPhrase.at(-1) !== "" + ) { plainPhrase.push(""); } else if (token.length === 1) { plainPhrase[plainPhrase.length - 1] = plainPhrase[plainPhrase.length - 1] + token; } else { - extraActions.push(token); + extraActions.add(token); } } if (chord.phrase?.[0] === 298) { - plainPhrase.push("suffix"); + tags.add("suffix"); } if ( ["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 ( - ["CTRL", "ALT", "GUI", "ENTER", "TAB"].some((it) => - extraActions.includes(it), - ) + ["CTRL", "ALT", "GUI", "ENTER", "TAB"].some((it) => extraActions.has(it)) ) { - plainPhrase.push("macro"); + tags.add("macro"); } if (chord.actions[0] !== 0) { - plainPhrase.push("compound"); + tags.add("compound"); } const input = chord.actions @@ -109,14 +111,15 @@ }); if (onlyPhrase) { - return plainPhrase.join(); + return plainPhrase.join(" "); } return [ ...plainPhrase, `+${input.join("+")}`, - ...new Set(extraActions), - ...new Set(extraCodes), + ...tags, + ...extraActions, + ...extraCodes, ].join(" "); }