From bf4c86e698f292d0421be673caebdda835d1dca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Fri, 8 Dec 2023 22:10:49 +0100 Subject: [PATCH] fix: legacy chords with commas and spaces --- src/lib/backup/compat/legacy-chords.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/backup/compat/legacy-chords.ts b/src/lib/backup/compat/legacy-chords.ts index 1825d4f8..7ab3afc1 100644 --- a/src/lib/backup/compat/legacy-chords.ts +++ b/src/lib/backup/compat/legacy-chords.ts @@ -1,6 +1,8 @@ import {KEYMAP_IDS} from "$lib/serial/keymap-codes" import type {CharaChordFile} from "$lib/share/chara-file" +const SPECIAL_KEYS = new Map([[" ", "SPACE"]]) + export function csvChordsToJson(csv: string): CharaChordFile { return { charaVersion: 1, @@ -9,18 +11,18 @@ export function csvChordsToJson(csv: string): CharaChordFile { .trim() .split("\n") .map(line => { - const [input, output] = line.split(",", 2) + const [input, output] = line.split(/,(?=[^,]*$)/, 2) return [ input.split("+").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0), output .trim() .split("") - .map(it => KEYMAP_IDS.get(it)?.code ?? 0), + .map(it => KEYMAP_IDS.get(SPECIAL_KEYS.get(it) ?? it)?.code ?? 0), ] }), } } export function isCsvChords(csv: string): boolean { - return /^([^+, ]+( *\+ *[^+, ]+)* *, *[^+, ]+ *(\n|(?=$)))+$/.test(csv) + return /^([^+]+( *\+ *[^+]+)* *, *[^+, ]+ *(\n|(?=$)))+$/.test(csv) }