From 17ae38177a55964e05bceaea74a053b9b47bc2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20No=C3=ABl?= Date: Sat, 27 Jan 2024 23:04:51 +0100 Subject: [PATCH 1/2] fix chordLyric renderer --- .../components/renderChordLyricLine.js | 22 ++++++++++------ .../components/renderChordLyricLine.spec.js | 25 ++++++++++++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/packages/chord-mark/src/renderer/components/renderChordLyricLine.js b/packages/chord-mark/src/renderer/components/renderChordLyricLine.js index f08a3210..7d80e6b4 100644 --- a/packages/chord-mark/src/renderer/components/renderChordLyricLine.js +++ b/packages/chord-mark/src/renderer/components/renderChordLyricLine.js @@ -124,15 +124,21 @@ function getAllBreakpoints(allChordTokens, allLyricTokens) { lyricLineBreakPoints ); - const longestLineBreakpoints = - _last(chordLineBreakPoints) > _last(lyricLineBreakPoints) - ? chordLineBreakPoints - : lyricLineBreakPoints; - - const lastBreakpoint = _last(allBreakpoints); - const remainingBreakpoints = longestLineBreakpoints.slice( - longestLineBreakpoints.indexOf(lastBreakpoint) + 1 + let shortestLineBreakpoints; + let longestLineBreakpoints; + + if (_last(chordLineBreakPoints) > _last(lyricLineBreakPoints)) { + longestLineBreakpoints = chordLineBreakPoints; + shortestLineBreakpoints = lyricLineBreakPoints; + } else { + longestLineBreakpoints = lyricLineBreakPoints; + shortestLineBreakpoints = chordLineBreakPoints; + } + + const remainingBreakpoints = longestLineBreakpoints.filter( + (bp) => bp > _last(shortestLineBreakpoints) ); + if (remainingBreakpoints.length) { allBreakpoints.push(...remainingBreakpoints); } diff --git a/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js b/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js index 553e6d58..ee89fe47 100644 --- a/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js +++ b/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js @@ -20,7 +20,6 @@ describe('renderChordLyricLine', () => { ['|', ''], ], ], - /**/ [ 'Longer chord line, 2', 'C G', @@ -201,6 +200,30 @@ describe('renderChordLyricLine', () => { ['|', ''], ], ], + /**/ + [ + 'Marcia Martienne', + 'Bm7 Bm7.. D7/F#..', + '_Voir ma bouche a_vide', + // + //|Bm7 |Bm7.. D7/F#. | + // Voir ma bouche avide + [ + ['|', ' '], + ['Bm7 ', 'Voir'], + [' ', ' '], + [' ', 'ma'], + [' ', ' '], + [' ', 'bouche'], + [' ', ' '], + ['|Bm7..', 'avide'], + [' ', ''], + ['D7/F#..', ''], + [' ', ''], + ['|', ''], + ], + { printChordsDuration: 'always' }, + ], /* */ ])('%s', (title, chordLine, lyricLine, pairs, options) => { test(`${chordLine} ${lyricLine}`, () => { From 9851628804f37b9376217b0cbbbe9747b156f49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20No=C3=ABl?= Date: Sat, 27 Jan 2024 23:09:55 +0100 Subject: [PATCH 2/2] remove extra comment line --- .../tests/unit/renderer/components/renderChordLyricLine.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js b/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js index ee89fe47..20c0ac27 100644 --- a/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js +++ b/packages/chord-mark/tests/unit/renderer/components/renderChordLyricLine.spec.js @@ -205,7 +205,6 @@ describe('renderChordLyricLine', () => { 'Marcia Martienne', 'Bm7 Bm7.. D7/F#..', '_Voir ma bouche a_vide', - // //|Bm7 |Bm7.. D7/F#. | // Voir ma bouche avide [