From 75f540c8f77b89366043ee0e4192ac44976a0b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20No=C3=ABl?= Date: Sat, 20 Jan 2024 14:56:09 +0100 Subject: [PATCH] Clean up old code --- .../chord-mark/src/parser/songLinesFactory.js | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/packages/chord-mark/src/parser/songLinesFactory.js b/packages/chord-mark/src/parser/songLinesFactory.js index c33b83b9..de2df65d 100644 --- a/packages/chord-mark/src/parser/songLinesFactory.js +++ b/packages/chord-mark/src/parser/songLinesFactory.js @@ -82,9 +82,7 @@ export default function songLinesFactory() { let blueprint = []; let blueprintIndex = 0; - let blueprintLine = ''; - let isRepeatingChords = false; let shouldMultiplySection = false; let shouldCopySection = false; @@ -141,13 +139,12 @@ export default function songLinesFactory() { shouldMultiplySection = currentSection.multiplyTimes > 0; previousSectionLabelLine = _cloneDeep(line); - if (!isFirstOfLabel(currentSection, allLines)) { - blueprint = getNthOfLabel(allLines, currentSection.label, 1); - blueprintIndex = 0; - isRepeatingChords = true; - } else { - isRepeatingChords = false; - } + blueprint = + currentSectionStats.count > 1 + ? getNthOfLabel(allLines, currentSection.label, 1) + : []; + blueprintIndex = 0; + return line; } @@ -239,8 +236,8 @@ export default function songLinesFactory() { } function repeatLinesFromBlueprint(line) { - if (isRepeatingChords && line.type !== lineTypes.SECTION_LABEL) { - blueprintLine = blueprint[blueprintIndex]; + if (blueprint.length && line.type !== lineTypes.SECTION_LABEL) { + let blueprintLine = blueprint[blueprintIndex]; let repeatedLine; while (shouldRepeatLineFromBlueprint(blueprintLine, line)) { @@ -259,6 +256,16 @@ export default function songLinesFactory() { } } + function shouldRepeatLineFromBlueprint(blueprintLine, currentLine) { + const nonRepeatableLinesTypes = [lineTypes.LYRIC, lineTypes.EMPTY_LINE]; + return ( + blueprintLine && + !nonRepeatableLinesTypes.includes(blueprintLine.type) && + blueprintLine.type !== currentLine.type && + currentLine.type !== lineTypes.EMPTY_LINE + ); + } + function copySection() { if (shouldCopySection) { const toCopy = getNthOfLabel( @@ -399,24 +406,6 @@ export default function songLinesFactory() { }; } -function isFirstOfLabel(currentLabel, allLines) { - return allLines.every( - (line) => - line.type === lineTypes.SECTION_LABEL && - line.model.label !== currentLabel.label - ); -} - -function shouldRepeatLineFromBlueprint(blueprintLine, currentLine) { - return ( - blueprintLine && - blueprintLine.type !== lineTypes.LYRIC && - blueprintLine.type !== lineTypes.EMPTY_LINE && - blueprintLine.type !== currentLine.type && - currentLine.type !== lineTypes.EMPTY_LINE - ); -} - function isLastLineOfSection(lineIndex, allSrcLines) { const nextLine = allSrcLines[lineIndex + 1]; return typeof nextLine === 'undefined' || isSectionLabel(nextLine);