From c4e3ebe7a0b3f9928c11998e157dc5eb3e3b6e2c Mon Sep 17 00:00:00 2001 From: Eana Hufwe Date: Fri, 3 Nov 2023 11:31:37 -0700 Subject: [PATCH 1/2] fix(jukebox): diff editor missing attachments --- .../musicFilesDetails/lyrics/DiffEditorDialog.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/jukebox/src/components/dashboard/musicFilesDetails/lyrics/DiffEditorDialog.tsx b/packages/jukebox/src/components/dashboard/musicFilesDetails/lyrics/DiffEditorDialog.tsx index ab67f0b3..e5507567 100644 --- a/packages/jukebox/src/components/dashboard/musicFilesDetails/lyrics/DiffEditorDialog.tsx +++ b/packages/jukebox/src/components/dashboard/musicFilesDetails/lyrics/DiffEditorDialog.tsx @@ -80,7 +80,7 @@ function applyDiff(source: string, edited: string): string { let relativeTimeOffset = 0; // relative time offset for when line break happens const finalizeLine = () => { if (resultTimeTags.length > 0) { - if (timeTagQueue.length > 0) { + if ((timeTagQueue?.length ?? 0) > 0) { const eolTimeTag = new WordTimeTagLabel( timeTagQueue[0].timeTag, timeTagQueue[0].index + resultLine.content.length - ptr @@ -118,14 +118,14 @@ function applyDiff(source: string, edited: string): string { const baseOffset = resultLine.content.length - ptr; if (text !== "\0") resultLine.content += text; ptr += text.length; - while (timeTagQueue.length > 0 && timeTagQueue[0]?.index < ptr) { + while ((timeTagQueue?.length ?? 0) > 0 && timeTagQueue[0]?.index < ptr) { const tag = timeTagQueue.shift(); tag.index += baseOffset; tag.timeTag += relativeTimeOffset; resultTimeTags.push(tag); } while ( - furiganaQueue.length > 0 && + (furiganaQueue?.length ?? 0) > 0 && furiganaQueue[0]?.range[1] <= ptr ) { const tag = furiganaQueue.shift(); @@ -133,10 +133,10 @@ function applyDiff(source: string, edited: string): string { tag.range[1] += baseOffset; resultFurigana.push(tag); } - while (dotsQueue.length > 0 && dotsQueue[0][1] <= ptr) { + while ((dotsQueue?.length ?? 0) > 0 && dotsQueue[0][1] <= ptr) { resultDots.push(dotsQueue.shift()[0]); } - while (tagsQueue.length > 0 && tagsQueue[0][1] <= ptr) { + while ((tagsQueue?.length ?? 0) > 0 && tagsQueue[0][1] <= ptr) { resultTags.push(tagsQueue.shift()[0]); } } else if (op === 1 && text !== "\n") { From 23e9aeb92282caac61bd308037fd8dfd42600c2c Mon Sep 17 00:00:00 2001 From: Eana Hufwe Date: Fri, 3 Nov 2023 12:53:32 -0700 Subject: [PATCH 2/2] fix(lyricova): completed inline quote should not be hanged --- .../public/PlainTextHangingPunct.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/lyricova/src/components/public/PlainTextHangingPunct.tsx b/packages/lyricova/src/components/public/PlainTextHangingPunct.tsx index afe5b672..d7e2285e 100644 --- a/packages/lyricova/src/components/public/PlainTextHangingPunct.tsx +++ b/packages/lyricova/src/components/public/PlainTextHangingPunct.tsx @@ -29,12 +29,29 @@ interface PlainTextHangingPunctProps { children: string; } +function shiftinPuncts(line: string, match: RegExpMatchArray | null, start: string, end: string ): RegExpMatchArray | null { + if (match && line.match(new RegExp(`${start}.*${end}`, "g"))) { + const front = match[1].split(start); + const back = match[3].split(end); + match[2] = `${start.repeat(front.length - 1)}${match[2]}${end.repeat(back.length - 1)}`; + match[1] = front.join(""); + match[3] = back.join(""); + } + return match; +} + export function PlainTextHangingPunct({ children, }: PlainTextHangingPunctProps) { const lines = children .split("\n") - .map((line) => line.match(/^([\p{Ps}\p{Pi}"]*)(.*?)(\p{Po}*)$/u)); + .map((line) => { + let match = line.match(/^([\p{Ps}\p{Pi}"]*)(.*?)(\p{Po}*)$/u); + match = shiftinPuncts(line, match, "「", "」"); + match = shiftinPuncts(line, match, "『", "』"); + match = shiftinPuncts(line, match, "「", "」"); + return match; + }); return ( <> {lines.map((line, idx) => (