From fc91f37b493d18ff4a7482e00e4a5eb6cd9b50f6 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Thu, 23 Apr 2020 10:14:47 +0000 Subject: [PATCH] Bug 1433073: part 3) Mimic old behavior of computing `mCommonInclusiveAncestors`. r=hsivonen This reverts a previously introduced regression. See the Bugzilla comments of this bug. The key consequence of this is change is that copy-pasting multiple click-selected table rows now works again for some applications (and shouldn't be broken for others). That's because the clipboard flavor "text/_moz_htmlcontext" doesn't contain a superfluous "" anymore. The fix could presumably be more elegant, but it would be hard to ensure no other applications relying on the old behavior break. Differential Revision: https://phabricator.services.mozilla.com/D71982 --- dom/base/nsDocumentEncoder.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dom/base/nsDocumentEncoder.cpp b/dom/base/nsDocumentEncoder.cpp index a01556726fd2..ae028b2471eb 100644 --- a/dom/base/nsDocumentEncoder.cpp +++ b/dom/base/nsDocumentEncoder.cpp @@ -464,6 +464,13 @@ nsresult nsDocumentEncoder::SerializeSelection() { } else if (prevNode) { // Went from a to a non- mDisableContextSerialize = false; + + // `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext` + // too. Update it here to mimic the old behavior. + mCommonInclusiveAncestors.Clear(); + nsContentUtils::GetInclusiveAncestors(prevNode->GetParentNode(), + mCommonInclusiveAncestors); + rv = SerializeRangeContextEnd(); NS_ENSURE_SUCCESS(rv, rv); prevNode = nullptr; @@ -482,6 +489,13 @@ nsresult nsDocumentEncoder::SerializeSelection() { rv = SerializeNodeEnd(*prevNode); NS_ENSURE_SUCCESS(rv, rv); mDisableContextSerialize = false; + + // `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext` + // too. Update it here to mimic the old behavior. + mCommonInclusiveAncestors.Clear(); + nsContentUtils::GetInclusiveAncestors(prevNode->GetParentNode(), + mCommonInclusiveAncestors); + rv = SerializeRangeContextEnd(); NS_ENSURE_SUCCESS(rv, rv); } @@ -984,7 +998,6 @@ nsresult nsDocumentEncoder::SerializeRangeContextStart( while (i > 0) { nsINode* node = aAncestorArray.ElementAt(--i); - if (!node) break; // Either a general inclusion or as immediate context