Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not consider key declarations when detecting empty sections #657

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/chord-mark/src/parser/lineTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
export default {
CHORD: 'chord',
CHORD_LINE_REPEATER: 'chordLineRepeater',
EMPTY_LINE: 'emptyLine',
KEY_DECLARATION: 'keyDeclaration',
LYRIC: 'lyric',
Expand Down
9 changes: 8 additions & 1 deletion packages/chord-mark/src/parser/songLinesFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,14 @@ export default function songLinesFactory() {

const currentSectionContent = remainingLines
.slice(0, nextSectionIndex !== -1 ? nextSectionIndex : undefined)
.filter((line) => !(isTimeSignature(line) || isEmptyLine(line))); //todo: add key definition line type as well
.filter(
(line) =>
!(
isTimeSignature(line) ||
isKeyDeclaration(line) ||
isEmptyLine(line)
)
);

return currentSectionContent.length === 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,45 @@ verseLine`;
expect(toText(rendered)).toBe(expected);
});

test('should not copy trailing directives lines', () => {
const input = `#v
verse
verse

3/4
key C
#c
chorus
chorus

#v

5/4
key A
#o
outro`;
const expected = `Verse 1
verse
verse

3/4
key: C
Chorus
chorus
chorus

Verse 2
verse
verse

5/4
key: A
Outro
outro`;
const rendered = renderSongText(input, { expandSectionCopy: true });
expect(toText(rendered)).toBe(expected);
});

test('should not repeat chords when autoRepeatChords === false', () => {
const input = `#v
A B
Expand Down Expand Up @@ -1066,35 +1105,6 @@ describe('Keys, accidental & transpose', () => {
'|Am7 |D7 |G |% |\n' +
'myVerse\n',
],
[
'',
'key A\n' +
'#c\n' +
'A\n' +
'_Chorus in A\n' +
'key C\n' +
'#v\n' +
'Am\n' +
'_Verse in C\n' +
'#c\n' +
'_Chorus in C\n' +
'#v\n' +
'_Verse in C',
'key: A\n' +
'Chorus 1\n' +
'|A |\n' +
' Chorus in A\n' +
'key: C\n' +
'Verse 1\n' +
'|Am |\n' +
' Verse in C\n' +
'Chorus 2\n' +
'|C |\n' +
' Chorus in C\n' +
'Verse 2\n' +
'|Am |\n' +
' Verse in C',
],
])('%s', (title, song, expected, options = {}) => {
test('renders with correct accidental', () => {
const rendered = renderSongText(song, {
Expand Down