From ed89cb06be05fbf0bdaf2ce282aec1e32073adbe Mon Sep 17 00:00:00 2001 From: Ian Chadwick Date: Tue, 27 Oct 2015 09:29:51 +0000 Subject: [PATCH] Fix for #1319 - html is pasted in reverse order Problem was in adding everything to the beginning of the right location the new nodes were being reversed so simple fix was to reverse the new nodes before they are appended --- src/paste.js | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/paste.js b/src/paste.js index 7b7f161d50..2d494ac402 100644 --- a/src/paste.js +++ b/src/paste.js @@ -133,38 +133,18 @@ define([ end : boundaries[1] }); var loc = Zip.go(zip.loc, zip.markers.start); - nodes.forEach(function (child) { + + // reverse the new nodes as we're inserting them at the beginning of the right hand content each time + nodes.reverse().map(function (child) { loc = Zip.split(loc, function (loc) { return Content.allowsNesting(Zip.after(loc).name(), child.nodeName); }); loc = Zip.insert(loc, Boromir(child)); }); + var markers = Zip.update(loc); return [markers.start, markers.end]; - - var result = MutationTrees.update(tree); - boundaries = result[1].map(Fn.partial(Paths.toBoundary, result[0].domNode())); - - var last = Arrays.last(nodes); - var next = Boundaries.nodeAfter(boundaries[1]); - - // Because we want to remove the unintentional line added at the end of - // the pasted content - if (next && ('P' === last.nodeName || 'DIV' === last.nodeName)) { - if (Html.hasInlineStyle(next)) { - boundaries[1] = Boundaries.fromEndOfNode(last); - // Move the next inline nodes into the last element - Dom.move(Dom.nodeAndNextSiblings(next, Html.hasLinebreakingStyle), last); - } else if (!Html.isVoidType(next) && !Html.isGroupContainer(next)) { - // Move the children of the last element into the beginning of - // the next block element - boundaries[1] = Dom.children(last).reduce(moveBeforeBoundary, Boundaries.create(next, 0)); - Dom.remove(last); - } - } - - return boundaries; } /**