Skip to content

Commit

Permalink
do not repeat last directives before the next section
Browse files Browse the repository at this point in the history
  • Loading branch information
no-chris committed Jan 24, 2024
1 parent 75f540c commit 03e9bef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/chord-mark/src/parser/helper/songs.js
@@ -1,4 +1,5 @@
import _cloneDeep from 'lodash/cloneDeep';
import _last from 'lodash/last';

import lineTypes from '../lineTypes';

Expand Down Expand Up @@ -85,5 +86,17 @@ export function getNthOfLabel(allLines, label, n) {
selected.push(line);
}
});

// remmove trailing directive lines
// because they likely apply to the next section
/**/
while (
_last(selected) &&
(_last(selected).type === lineTypes.KEY_DECLARATION ||
_last(selected).type === lineTypes.TIME_SIGNATURE)
) {
selected.pop();
}
/** */
return selected;
}
7 changes: 6 additions & 1 deletion packages/chord-mark/tests/unit/parser/helpers/song.spec.js
Expand Up @@ -152,20 +152,24 @@ describe('getNthOfLabel', () => {
expect(getNthOfLabel).toBeInstanceOf(Function);
});

test('Should return the section identified by its label and index', () => {
test('Should return the section identified by its label and index, without trailing directives', () => {
const song2 = `
#v
Verse1-line1
Verse1-line2
Verse1-line3
Verse1-line4
4/4
#v
Verse2-line1
Verse2-line2
Verse2-line3
Verse2-line4
key B
3/4
#v
Verse3-line1
Verse3-line2
Expand All @@ -186,6 +190,7 @@ Verse3-line4`;
'Verse2-line3',
'Verse2-line4',
'',
'',
];
const v3 = [
'Verse3-line1',
Expand Down

0 comments on commit 03e9bef

Please sign in to comment.