diff --git a/client/src/app/core/ui-services/diff.service.spec.ts b/client/src/app/core/ui-services/diff.service.spec.ts index 48a0e4bcc..186f007d8 100644 --- a/client/src/app/core/ui-services/diff.service.spec.ts +++ b/client/src/app/core/ui-services/diff.service.spec.ts @@ -886,6 +886,22 @@ describe('DiffService', () => { } )); + it('detects inline insertions exceeding block paragraphs', inject([DiffService], (service: DiffService) => { + const before = + '
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
\n' + + 'At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
', + after = + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Insertion 1
\n' + + 'Insertion 2 At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
'; + + const diff = service.diff(before, after); + + expect(diff).toBe( + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Insertion 1
\n' + + 'Insertion 2 At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
' + ); + })); + it('does not lose formattings when multiple lines are deleted', inject( [DiffService], (service: DiffService) => { diff --git a/client/src/app/core/ui-services/diff.service.ts b/client/src/app/core/ui-services/diff.service.ts index f565fd2f7..1cc637550 100644 --- a/client/src/app/core/ui-services/diff.service.ts +++ b/client/src/app/core/ui-services/diff.service.ts @@ -2001,14 +2001,6 @@ export class DiffService { } ); - //...
=> ...... + diffUnnormalized = diffUnnormalized.replace( + /<(ins|del)>([\s\S]*?)<\/(p|div|blockquote|li)>\s*<(p|div|blockquote|li)([^>]*)>([\s\S]*?)<\/\1>/gi, + ( + whole: string, + insDel: string, + content1: string, + blockEnd: string, + blockStart: string, + blockAttrs: string, + content2: string + ): string => { + if (this.isValidInlineHtml(content1) && this.isValidInlineHtml(content2)) { + return ( + '<' + + insDel + + '>' + + content1 + + '' + + insDel + + '>' + + blockEnd + + '>' + + '<' + + blockStart + + blockAttrs + + '><' + + insDel + + '>' + + content2 + + '' + + insDel + + '>' + ); + } else { + return whole; + } + } + ); + // Cleanup leftovers from the operation above, when -tags ore -tags are left // around block tags. It should be safe to remove them and just leave the whitespaces. diffUnnormalized = diffUnnormalized.replace(