Merge pull request #4631 from CatoTH/Bugfix-replacing-text-at-end-of-paragraph

Bugfix: inline diff for replaced text at end of paragraph
This commit is contained in:
Emanuel Schütze 2019-04-25 22:26:38 +02:00 committed by GitHub
commit b7ae5fd8a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -857,6 +857,21 @@ describe('DiffService', () => {
);
}));
it('does handle insertions at the end of a paragraph correctly', inject(
[DiffService],
(service: DiffService) => {
const before =
'<p>Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p>\n<p>Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>',
after =
'<p>Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p>\n<p>Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, NEU NEU NEU.</p>';
const diff = service.diff(before, after);
expect(diff).toBe(
'<p>Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p>\n<p>Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, <del>augue velit cursus nunc,</del><ins>NEU NEU NEU.</ins></p>'
);
}
));
it('does not break when an insertion followes a beginning tag occuring twice', inject(
[DiffService],
(service: DiffService) => {

View File

@ -2001,6 +2001,14 @@ export class DiffService {
}
);
// <del>deleted text</P></del><ins>inserted.</P></ins> => <del>deleted tet</del><ins>inserted.</ins></P>
diffUnnormalized = diffUnnormalized.replace(
/<del>([^<]*)<\/(p|div|blockquote|li)><\/del><ins>([^<]*)<\/\2><\/ins>\s*$/gi,
(whole: string, deleted: string, tag: string, inserted: string): string => {
return '<del>' + deleted + '</del><ins>' + inserted + '</ins></' + tag + '>';
}
);
// If larger inserted HTML text contains block elements, we separate the inserted text into
// inline <ins> elements and "insert"-class-based block elements.
// <ins>...<div>...</div>...</ins> => <ins>...</ins><div class="insert">...</div><ins>...</ins>