Skip to content

Commit

Permalink
Remove obsolete DiffDOM workaround
Browse files Browse the repository at this point in the history
Workaround is no longer necessary as of DiffDOM 4.2.1

See fiduswriter/diffDOM#90

Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
  • Loading branch information
clarkf committed Jan 29, 2023
1 parent c996776 commit d89501c
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions src/utils/MessageDiffUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit d89501c

Please sign in to comment.