Merge pull request #4595 from matrix-org/t3chguy/edit_crash

Fix message edits dialog being wrong and sometimes crashing
pull/21833/head
Michael Telatynski 2020-05-14 15:48:19 +01:00 committed by GitHub
commit 087d514c4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -77,8 +77,6 @@ function findRefNodes(root, route, isAddition) {
const end = isAddition ? route.length - 1 : route.length; const end = isAddition ? route.length - 1 : route.length;
for (let i = 0; i < end; ++i) { for (let i = 0; i < end; ++i) {
refParentNode = refNode; refParentNode = refNode;
// Lists don't have appropriate child nodes we can use.
if (!refNode.childNodes[route[i]]) continue;
refNode = refNode.childNodes[route[i]]; refNode = refNode.childNodes[route[i]];
} }
return {refNode, refParentNode}; return {refNode, refParentNode};
@ -190,10 +188,11 @@ function renderDifferenceInDOM(originalRootNode, diff, diffMathPatch) {
break; break;
} }
case "addTextElement": { case "addTextElement": {
if (diff.value !== "\n") { // XXX: sometimes diffDOM says insert a newline when there shouldn't be one
const insNode = wrapInsertion(stringAsTextNode(diff.value)); // but we must insert the node anyway so that we don't break the route child IDs.
insertBefore(refParentNode, refNode, insNode); // See https://github.com/fiduswriter/diffDOM/issues/100
} const insNode = wrapInsertion(stringAsTextNode(diff.value !== "\n" ? diff.value : ""));
insertBefore(refParentNode, refNode, insNode);
break; break;
} }
// e.g. when changing a the href of a link, // e.g. when changing a the href of a link,