+ // Make sure there is no class difference.
+ InsetText in;
+ // This works without copying any paragraph data because we have
+ // a specialized swap method for ParagraphList. This is important
+ // since we store pointers to insets at some places and we don't
+ // want to invalidate them.
+ insertion.swap(in.paragraphs());
+ cap::switchBetweenClasses(textclass, tc, in, errorlist);
+ insertion.swap(in.paragraphs());
+
+ ParagraphList::iterator tmpbuf = insertion.begin();
+ int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
+
+ depth_type max_depth = pars[pit].getMaxDepthAfter();
+
+ for (; tmpbuf != insertion.end(); ++tmpbuf) {
+ // If we have a negative jump so that the depth would
+ // go below 0 depth then we have to redo the delta to
+ // this new max depth level so that subsequent
+ // paragraphs are aligned correctly to this paragraph
+ // at level 0.
+ if (int(tmpbuf->params().depth()) + depth_delta < 0)
+ depth_delta = 0;
+
+ // Set the right depth so that we are not too deep or shallow.
+ tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
+ if (tmpbuf->params().depth() > max_depth)
+ tmpbuf->params().depth(max_depth);
+
+ // Only set this from the 2nd on as the 2nd depends
+ // for maxDepth still on pit.
+ if (tmpbuf != insertion.begin())
+ max_depth = tmpbuf->getMaxDepthAfter();
+
+ // Set the inset owner of this paragraph.
+ tmpbuf->setInsetOwner(pars[pit].inInset());
+ for (pos_type i = 0; i < tmpbuf->size(); ++i) {
+ if (tmpbuf->getChar(i) == Paragraph::META_INSET &&
+ !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
+ // do not track deletion of invalid insets
+ tmpbuf->eraseChar(i--, false);