Fix order of corrections

This commit is contained in:
Ramon Wenger 2020-01-07 17:23:52 +01:00 committed by Ramon Wenger
parent bc9bf8cdec
commit 2b9d14222d
2 changed files with 13 additions and 11 deletions

View File

@ -17,7 +17,7 @@ describe('Spellcheck', () => {
teaser: 'Die Berufsbildung ist ein neuer Lebensabschnit', teaser: 'Die Berufsbildung ist ein neuer Lebensabschnit',
intro: '\n <p>Sie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung \u00fcbernommen.</p>\n <p>Wie erging es Ihnen am ersten Arbeits- und Schultag?</p>\n ', intro: '\n <p>Sie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung \u00fcbernommen.</p>\n <p>Wie erging es Ihnen am ersten Arbeits- und Schultag?</p>\n ',
slug: 'lohn-und-budget', slug: 'lohn-und-budget',
heroImage: 'https://hep-skillbox-files-prod.s3-eu-central-1.amazonaws.com/original_images/dummy_7bzqodY.jpg', heroImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
solutionsEnabled: false, solutionsEnabled: false,
bookmark: {note: null, '__typename': 'ModuleBookmarkNode'}, bookmark: {note: null, '__typename': 'ModuleBookmarkNode'},
__typename: 'ModuleNode', __typename: 'ModuleNode',

View File

@ -15,17 +15,19 @@
} }
let parts = []; let parts = [];
let index = 0; let index = 0;
this.corrections.forEach(current => { [...this.corrections] // no side effects, as sort changes the source array
parts.push({ .sort((e1, e2) => e1.offset - e2.offset)
correct: true, .forEach(current => {
text: this.text.substring(index, current.offset) parts.push({
correct: true,
text: this.text.substring(index, current.offset)
});
parts.push({
correct: false,
text: this.text.substring(current.offset, current.offset + current.length)
});
index = current.offset + current.length
}); });
parts.push({
correct: false,
text: this.text.substring(current.offset, current.offset + current.length)
});
index = current.offset + current.length
});
parts.push({ parts.push({
correct: true, correct: true,
text: this.text.substring(index, this.text.length + 1) text: this.text.substring(index, this.text.length + 1)