summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/HTMLEditorDataTransfer.cpp
diff options
context:
space:
mode:
authorNew Tobin Paradigm <email@mattatobin.com>2018-04-16 08:24:14 -0400
committerGitHub <noreply@github.com>2018-04-16 08:24:14 -0400
commita66e6546c361d238b0179af18e26bf18aa4a7eb9 (patch)
treeadd968413c1d17d58ae0835b7051b7d38e4648f3 /editor/libeditor/HTMLEditorDataTransfer.cpp
parentded797b8bb211a2e5591d4b7d21c017a7c23b67b (diff)
parent05bb04a6514d2e6557dc0697c34a56cfd2c399a4 (diff)
downloadUXP-a66e6546c361d238b0179af18e26bf18aa4a7eb9.tar
UXP-a66e6546c361d238b0179af18e26bf18aa4a7eb9.tar.gz
UXP-a66e6546c361d238b0179af18e26bf18aa4a7eb9.tar.lz
UXP-a66e6546c361d238b0179af18e26bf18aa4a7eb9.tar.xz
UXP-a66e6546c361d238b0179af18e26bf18aa4a7eb9.zip
Merge pull request #173 from janekptacijarabaci/html_table_editor_contenteditable_1
moebius#190: HTML - table - editor (contenteditable) - post process node array to remove all descendants of replacement node
Diffstat (limited to 'editor/libeditor/HTMLEditorDataTransfer.cpp')
-rw-r--r--editor/libeditor/HTMLEditorDataTransfer.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/editor/libeditor/HTMLEditorDataTransfer.cpp b/editor/libeditor/HTMLEditorDataTransfer.cpp
index b9cd8adb9..ed350c0dd 100644
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -2382,27 +2382,26 @@ HTMLEditor::ReplaceOrphanedStructure(
}
// If we found substructure, paste it instead of its descendants.
- // Only replace with the substructure if all the nodes in the list are
- // descendants.
- bool shouldReplaceNodes = true;
- for (uint32_t i = 0; i < aNodeArray.Length(); i++) {
+ // Postprocess list to remove any descendants of this node so that we don't
+ // insert them twice.
+ uint32_t removedCount = 0;
+ uint32_t originalLength = aNodeArray.Length();
+ for (uint32_t i = 0; i < originalLength; i++) {
uint32_t idx = aStartOrEnd == StartOrEnd::start ?
- i : (aNodeArray.Length() - i - 1);
+ (i - removedCount) : (originalLength - i - 1);
OwningNonNull<nsINode> endpoint = aNodeArray[idx];
- if (!EditorUtils::IsDescendantOf(endpoint, replaceNode)) {
- shouldReplaceNodes = false;
- break;
+ if (endpoint == replaceNode ||
+ EditorUtils::IsDescendantOf(endpoint, replaceNode)) {
+ aNodeArray.RemoveElementAt(idx);
+ removedCount++;
}
}
- if (shouldReplaceNodes) {
- // Now replace the removed nodes with the structural parent
- aNodeArray.Clear();
- if (aStartOrEnd == StartOrEnd::end) {
- aNodeArray.AppendElement(*replaceNode);
- } else {
- aNodeArray.InsertElementAt(0, *replaceNode);
- }
+ // Now replace the removed nodes with the structural parent
+ if (aStartOrEnd == StartOrEnd::end) {
+ aNodeArray.AppendElement(*replaceNode);
+ } else {
+ aNodeArray.InsertElementAt(0, *replaceNode);
}
}