From e533fbad6dbce4cbb24fddf3648e09ff880050ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?=
Date: Thu, 25 Apr 2019 22:07:00 +0200
Subject: [PATCH] Bugfix: inline diff for replaced text at end of paragraph
---
.../src/app/core/ui-services/diff.service.spec.ts | 15 +++++++++++++++
client/src/app/core/ui-services/diff.service.ts | 8 ++++++++
2 files changed, 23 insertions(+)
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 23ecdabcb..48a0e4bcc 100644
--- a/client/src/app/core/ui-services/diff.service.spec.ts
+++ b/client/src/app/core/ui-services/diff.service.spec.ts
@@ -857,6 +857,21 @@ describe('DiffService', () => {
);
}));
+ it('does handle insertions at the end of a paragraph correctly', inject(
+ [DiffService],
+ (service: DiffService) => {
+ const before =
+ 'Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.
\nDuis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
',
+ after =
+ 'Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.
\nDuis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, NEU NEU NEU.
';
+ const diff = service.diff(before, after);
+
+ expect(diff).toBe(
+ 'Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.
\nDuis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,NEU NEU NEU.
'
+ );
+ }
+ ));
+
it('does not break when an insertion followes a beginning tag occuring twice', 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 30b39a29b..f565fd2f7 100644
--- a/client/src/app/core/ui-services/diff.service.ts
+++ b/client/src/app/core/ui-services/diff.service.ts
@@ -2001,6 +2001,14 @@ export class DiffService {
}
);
+ // deleted text
inserted. => deleted tetinserted.
+ diffUnnormalized = diffUnnormalized.replace(
+ /([^<]*)<\/(p|div|blockquote|li)><\/del>([^<]*)<\/\2><\/ins>\s*$/gi,
+ (whole: string, deleted: string, tag: string, inserted: string): string => {
+ return '' + deleted + '' + inserted + '' + tag + '>';
+ }
+ );
+
// If larger inserted HTML text contains block elements, we separate the inserted text into
// inline elements and "insert"-class-based block elements.
// ......
... => ......
...