mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-04 14:58:37 +09:00
moebius#190: HTML - table - editor (contenteditable) - post process node array to remove all descendants of replacement node
https://github.com/MoonchildProductions/moebius/issues/190
This commit is contained in:
parent
b50357b7ae
commit
aa1df43166
3 changed files with 82 additions and 16 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue