From d89501cbb104478d6e8df4fde91c44c7e574b85a Mon Sep 17 00:00:00 2001 From: Clark Fischer Date: Sun, 29 Jan 2023 13:49:20 -0800 Subject: [PATCH] Remove obsolete DiffDOM workaround Workaround is no longer necessary as of DiffDOM 4.2.1 See https://github.com/fiduswriter/diffDOM/issues/90 Signed-off-by: Clark Fischer --- src/utils/MessageDiffUtils.tsx | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/src/utils/MessageDiffUtils.tsx b/src/utils/MessageDiffUtils.tsx index 4943bbd6216..f8b638617a9 100644 --- a/src/utils/MessageDiffUtils.tsx +++ b/src/utils/MessageDiffUtils.tsx @@ -259,33 +259,6 @@ function renderDifferenceInDOM(originalRootNode: Node, diff: IDiff, diffMathPatc } } -function routeIsEqual(r1: number[], r2: number[]): boolean { - return r1.length === r2.length && !r1.some((e, i) => e !== r2[i]); -} - -// workaround for https://github.com/fiduswriter/diffDOM/issues/90 -function filterCancelingOutDiffs(originalDiffActions: IDiff[]): IDiff[] { - const diffActions = originalDiffActions.slice(); - - for (let i = 0; i < diffActions.length; ++i) { - const diff = diffActions[i]!; - if (diff.action === "removeTextElement") { - const nextDiff = diffActions[i + 1]; - const cancelsOut = - nextDiff && - nextDiff.action === "addTextElement" && - nextDiff.text === diff.text && - routeIsEqual(nextDiff.route, diff.route); - - if (cancelsOut) { - diffActions.splice(i, 2); - } - } - } - - return diffActions; -} - /** * Renders a message with the changes made in an edit shown visually. * @param {IContent} originalContent the content for the base message @@ -300,9 +273,7 @@ export function editBodyDiffToHtml(originalContent: IContent, editContent: ICont // diffActions is an array of objects with at least a `action` and `route` // property. `action` tells us what the diff object changes, and `route` where. // `route` is a path on the DOM tree expressed as an array of indices. - const originaldiffActions = dd.diff(originalBody, editBody); - // work around https://github.com/fiduswriter/diffDOM/issues/90 - const diffActions = filterCancelingOutDiffs(originaldiffActions); + const diffActions = dd.diff(originalBody, editBody); // for diffing text fragments const diffMathPatch = new DiffMatchPatch(); // parse the base html message as a DOM tree, to which we'll apply the differences found.